Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.3 kB
3
Indexable
Never
public async Task<object> AddNewProducts(Sample temp)    // Method to add new products
  {
       try
       {
           Inventory Inv= new Inventory();
         _context.Database.EnsureCreated();
             var inventory =await(from i in _context.Inventory 
                                     where i.ProductName == temp.ProductName
                                     select new {i.ProductId,i.ProductName,i.Price,i.Quantity,temp.Category,i.ProductImage} ).ToListAsync();       

            if(inventory != null) {
                 return "Dupliate Entry";
            }
            Inv.ProductName=temp.ProductName;
            Inv.Price=temp.Price;
            Inv.Quantity=temp.Quantity;
            Inv.ProductImage=temp.ProductImage;
            var result = (from i in _context.Categorytable
                                where i.Category == temp.Category
                                select new {i.CategoryId}).ToString();
            int t=int.Parse(result);
            Inv.CategoryId=t;
            Inv.IsDelete=true;                 
            _context.Inventory.Add(Inv);
            _context.SaveChanges();
            return  inventory;
       }
     catch(Exception ex)
        {
            throw new Exception(" " ,ex);
        }

  }
Leave a Comment