Untitled

 avatar
unknown
plain_text
a year ago
1.3 kB
6
Indexable
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);
        }

  }
Editor is loading...
Leave a Comment