public void SaveDishesCategory(DishesСategory entity) { if (entity.Id == default) { context.Entry(entity).State = EntityState.Added; } else { context.Entry(entity).State = EntityState.Modified; } context.SaveChanges(); }
public IActionResult EditDishCategory(DishesСategory model, string titleIconName) { if (ModelState.IsValid) { if (model.Id == default) { var category = dataManager.DishesCategories.GetDishesCategories().OrderBy(x => x.IndexNumber).Last(); model.IndexNumber = category.IndexNumber + 1; model.TitleIconPath = titleIconName; } if (titleIconName != null) { model.TitleIconPath = titleIconName; } dataManager.DishesCategories.SaveDishesCategory(model); } return(RedirectToAction(nameof(DishesController.Index), nameof(DishesController).CutController())); }
public IActionResult Down(Guid id) { DishesСategory currenCategory = dataManager.DishesCategories.GetDishesCategoryById(id); DishesСategory nextСategory; if (currenCategory == dataManager.DishesCategories.GetDishesCategories().OrderBy(x => x.IndexNumber).Last()) { nextСategory = dataManager.DishesCategories.GetDishesCategoryByIndexNumber(1); nextСategory.IndexNumber = currenCategory.IndexNumber; currenCategory.IndexNumber = 1; } else { nextСategory = dataManager.DishesCategories.GetDishesCategoryByIndexNumber(currenCategory.IndexNumber + 1); --nextСategory.IndexNumber; ++currenCategory.IndexNumber; } dataManager.DishesCategories.SaveDishesCategory(currenCategory); dataManager.DishesCategories.SaveDishesCategory(nextСategory); return(RedirectToAction(nameof(DishesController.Index), nameof(DishesController).CutController())); }
public IActionResult Up(Guid id) { DishesСategory currenCategory = dataManager.DishesCategories.GetDishesCategoryById(id); DishesСategory previousСategory; if (currenCategory.IndexNumber - 1 == 0) { previousСategory = dataManager.DishesCategories.GetDishesCategories().OrderBy(x => x.IndexNumber).Last(); currenCategory.IndexNumber = previousСategory.IndexNumber; previousСategory.IndexNumber = 1; } else { previousСategory = dataManager.DishesCategories.GetDishesCategoryByIndexNumber(currenCategory.IndexNumber - 1); ++previousСategory.IndexNumber; --currenCategory.IndexNumber; } dataManager.DishesCategories.SaveDishesCategory(currenCategory); dataManager.DishesCategories.SaveDishesCategory(previousСategory); return(RedirectToAction(nameof(DishesController.Index), nameof(DishesController).CutController())); }