public async Task EditDishExtraType(DishExtraType editDishExtraType) { var editExtraType = await _context.DishExtraTypes.FindAsync(editDishExtraType.DishExtraTypeId); editExtraType.TypeName = editDishExtraType.TypeName; editExtraType.ChooseMultiple = editDishExtraType.ChooseMultiple; editExtraType.Placeholder = editDishExtraType.Placeholder; editExtraType.Status = editDishExtraType.Status; _context.DishExtraTypes.Update(editExtraType); await _context.SaveChangesAsync(); }
public async Task <IActionResult> AddDishExtraType(DishExtraType extra, int returnId) { try { await _service.AddDishExtraType(extra); return(RedirectToAction("Edit", "Dishes", new { @id = returnId })); } catch (Exception ex) { return(RedirectToAction("Edit", "Dishes", new { @id = returnId })); } }
public async Task <JsonResult> DuplicateDish(int id) { try { var dish = await _service.GetDish(id); var cloneDish = new Dish { Allergies = dish.Allergies, BasePrice = dish.BasePrice, Description = dish.Description, DishCategoryId = dish.DishCategoryId, DishName = dish.DishName, SubName = dish.SubName, Rating = dish.Rating }; //var dishSizes = new List<DishSize>(); //foreach (var item in dish.DishSizes) //{ // var size = new DishSize // { // BasePrice = item.BasePrice, // Diameter = item.Diameter, // Size = item.Size // }; // dishSizes.Add(size); //} //cloneDish.DishSizes = dishSizes; //var dishExtraTypes = new List<DishExtraType>(); //foreach (var item in dish.DishExtraTypes) //{ // var dishExtraType = new DishExtraType // { // ChooseMultiple = item.ChooseMultiple, // Status = item.Status, // TypeName = item.TypeName // }; // var dishExtras = new List<DishExtra>(); // foreach (var extra in item.DishExtras) // { // var dishExtra = new DishExtra // { // ExtraName = extra.ExtraName, // ExtraPrice = extra.ExtraPrice, // Allergies = extra.Allergies, // IsAvailable = extra.IsAvailable // }; // var sizeToppingPrices = new List<SizeToppingPrice>(); // foreach (var topppingSize in extra.SizeToppingPrices) // { // var toppingPrice = new SizeToppingPrice // { // SizeName = topppingSize.SizeName, // Price = topppingSize.Price // }; // sizeToppingPrices.Add(toppingPrice); // } // dishExtra.SizeToppingPrices = sizeToppingPrices; // dishExtras.Add(dishExtra); // } // dishExtraType.DishExtras = dishExtras; // dishExtraTypes.Add(dishExtraType); //} //cloneDish.DishExtraTypes = dishExtraTypes; var dishSizes = new List <DishSize>(); dish.DishSizes.ToList().ForEach(s => { var size = new DishSize { BasePrice = s.BasePrice, Diameter = s.Diameter, Size = s.Size }; dishSizes.Add(size); }); cloneDish.DishSizes = dishSizes; var dishExtraTypes = new List <DishExtraType>(); dish.DishExtraTypes.ToList().ForEach(s => { var dishExtraType = new DishExtraType { ChooseMultiple = s.ChooseMultiple, Status = s.Status, TypeName = s.TypeName }; var dishExtras = new List <DishExtra>(); s.DishExtras.ToList().ForEach(a => { var dishExtra = new DishExtra { ExtraName = a.ExtraName, ExtraPrice = a.ExtraPrice, Allergies = a.Allergies, IsAvailable = a.IsAvailable }; var sizeToppingPrices = new List <SizeToppingPrice>(); a.SizeToppingPrices.ToList().ForEach(b => { var toppingPrice = new SizeToppingPrice { SizeName = b.SizeName, Price = b.Price }; sizeToppingPrices.Add(toppingPrice); }); dishExtra.SizeToppingPrices = sizeToppingPrices; dishExtras.Add(dishExtra); }); dishExtraType.DishExtras = dishExtras; dishExtraTypes.Add(dishExtraType); }); cloneDish.DishExtraTypes = dishExtraTypes; await _service.AddDish(cloneDish); return(Json("Success")); } catch (Exception ex) { return(Json("Failed")); } }
//Helper Functions public async Task AddDishExtraType(DishExtraType dishExtraType) { await _context.DishExtraTypes.AddAsync(dishExtraType); await _context.SaveChangesAsync(); }