Exemplo n.º 1
0
        public async Task <object> AddUpdateItem(ItemViewModel itemViewModel, string UserName)
        {
            MyMenu.Shared.Models.Item item = new MyMenu.Shared.Models.Item();
            item.Name              = itemViewModel.Name;
            item.Description       = itemViewModel.Description;
            item.ImgUrl            = itemViewModel.ImgUrl;
            item.CategoryId        = itemViewModel.CategoryId;
            item.Price             = itemViewModel.Price;
            item.PriceWithDiscount = itemViewModel.PriceWithDiscount;
            item.CreatedBy         = UserName;
            item.CreatedAt         = DateTime.Now;
            item.UpdatedBy         = UserName;
            item.UpdatedAt         = DateTime.Now;
            item.IsActive          = true;
            item.IsDelete          = false;
            context.Item.Add(item);
            await context.SaveChangesAsync();

            return(item);


            //var item = await context.Item.FindAsync(itemViewModel.Id);
            // item.Name = itemViewModel.Name;
            // item.Description = itemViewModel.Description;
            // item.ImgUrl = itemViewModel.ImgUrl;
            // item.CategoryId = itemViewModel.CategoryId;
            // item.Price = itemViewModel.Price;
            // item.PriceWithDiscount = itemViewModel.PriceWithDiscount;
            // item.UpdatedAt = DateTime.Now;
            // item.UpdatedBy = UserName;
            // item.IsActive = itemViewModel.IsActive;
            // context.Item.Update(item);
            // await context.SaveChangesAsync();
            // return item;
        }
Exemplo n.º 2
0
        public async Task AddItem(ItemViewModel newitem)
        {
            MyMenu.Shared.Models.Item item = new MyMenu.Shared.Models.Item();
            item.Name              = newitem.Name;
            item.Description       = newitem.Description;
            item.ImgUrl            = newitem.ImgUrl;
            item.CategoryId        = newitem.CategoryId;
            item.CompanyId         = newitem.CompanyId;
            item.Price             = newitem.Price;
            item.PriceWithDiscount = newitem.PriceWithDiscount;
            item.DiscountId        = newitem.DiscountId;
            item.CreatedAt         = DateTime.Now;
            item.UpdatedAt         = DateTime.Now;
            item.IsActive          = newitem.IsActive;
            item.IsDelete          = false;
            await context.Item.AddAsync(item);

            await context.SaveChangesAsync();
        }