public JsonResult Edit(DishStore store, int?categoryId, [System.Web.Http.FromBody] EditCategory edit) { if (!categoryId.HasValue) { return(ApiModel(message: "参数不能为空[categoryId]")); } DishCategory category = DishCategoryBLL.SingleModel.GetModel(categoryId.Value); if (category == null || category.storeId != store.id) { return(ApiModel(message: "非法操作")); } category.title = edit.Name; category.img = edit.Icon; category.name_info = edit.Description; category.is_show = edit.Display ? 1 : 0; category.is_order = edit.Sort; category.updateTime = DateTime.Now; bool success = DishCategoryBLL.SingleModel.Update(category, "title,img,name_info,is_show,is_order,updateTime"); return(ApiModel(isok: success, message: success ? "编辑成功" : "编辑失败")); }
public async Task <Unit> Handle(CreateDishCategoryCommand request, CancellationToken cancellationToken) { var user = await _userAuth.GetCurrentUser(); if (user == null) { throw new RestException(HttpStatusCode.Unauthorized, new { User = "******" }); } if (await _dishCategory.IsDishCategoryExits(request.Title, user.Id)) { throw new RestException(HttpStatusCode.BadRequest, new { DishCategory = "Already exist" }); } var toCreateDish = new DishCategory { Title = request.Title }; bool createdDish = await _dishCategory.Create(user.Id, toCreateDish); if (createdDish) { return(Unit.Value); } throw new Exception("Problem creating dish category"); }
public async Task <bool> Create(int userId, DishCategory dishCategory) { try { string insertCommandText = @"INSERT INTO DishCategory(DishCategoryTitle, UserId) OUTPUT INSERTED.DishCategoryId values (@dishCategoryTitle, @userId)"; SqlParameter dish_title = new SqlParameter("@dishCategoryTitle", dishCategory.Title); SqlParameter user_id = new SqlParameter("@userId", userId); var identityId = await SqlHelper.ExecuteScalarAsync(conStr, insertCommandText, CommandType.Text, dish_title, user_id); if (identityId != null) { return(true); } return(false); } catch (Exception) { throw new Exception("Problem creating dish category"); } }
public IActionResult Edit(int id, [Bind("DishCategoryId,Name")] DishCategory dishCategory) { if (id != dishCategory.DishCategoryId) { return(NotFound()); } if (ModelState.IsValid) { try { _dishCategoryService.Edit(dishCategory); } catch (DbUpdateConcurrencyException) { if (!DishCategoryExists(dishCategory.DishCategoryId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(dishCategory)); }
public async Task <IActionResult> Edit(int id, [Bind("DishCategoryId,Description")] DishCategory dishCategory) { if (id != dishCategory.DishCategoryId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(dishCategory); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DishCategoryExists(dishCategory.DishCategoryId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(dishCategory)); }
public async Task Delete(int id) { DishCategory dishCategory = await _context.DishCategories.FindAsync(id); _context.DishCategories.Remove(dishCategory); await _context.SaveChangesAsync(); }
public async Task <Unit> Handle(UpdateDishCategoryCommand request, CancellationToken cancellationToken) { var user = await _userAuth.GetCurrentUser(); if (user == null) { throw new RestException(HttpStatusCode.Unauthorized, new { User = "******" }); } var dishCategory = await _dishCategory.GetDishCategory(request.DishCategoryId, user.Id); if (dishCategory == null) { throw new RestException(HttpStatusCode.NotFound, new { DishCategory = "Not found" }); } var updateDishCategory = new DishCategory { Title = request.Title ?? dishCategory.Title, }; var success = await _dishCategory.Update(user.Id, request.DishCategoryId, updateDishCategory); if (success) { return(Unit.Value); } throw new Exception("Problem saving changes"); }
public ActionResult Create(DishCategory dishCategory, IList<DishCategory_Locale> locales) { foreach (var locale in locales) locale.DishCategory = dishCategory; dishCategory.Name = dishCategory.DishCategories_Locale.First(l => l.Culture == SupportedCulture.En).DisplayName.Replace(" ", "-"); if (ModelState.IsValid) if (db.DishCategories.Any(dc => dc.Name == dishCategory.Name)) ModelState.AddModelError("Unique", Resource.Unique); if (ModelState.IsValid) { dishCategory.Order = db.DishCategories.Any() ? db.DishCategories.Max(dc => dc.Order) + 1 : 1; db.DishCategories.AddObject(dishCategory); db.SaveChanges(); TempData["Result"] = Resource.ChangesSaved; return RedirectToAction("Index"); } else { return Create(); } }
public async Task <List <DishCategory> > GetDishCategories(int userId) { try { List <DishCategory> dishCategories = new List <DishCategory>(); string selectCommandText = @"SELECT * FROM DishCategory WHERE UserId=@userId"; SqlParameter user_id = new SqlParameter("@userId", SqlDbType.Int); user_id.Value = userId; using (SqlDataReader reader = await SqlHelper.ExecuteReaderAsync(conStr, selectCommandText, CommandType.Text, user_id)) { while (reader.Read()) { var dishCategory = new DishCategory(); dishCategory.Id = (int)reader["DishCategoryId"]; dishCategory.Title = (string)reader["DishCategoryTitle"]; dishCategories.Add(dishCategory); } await reader.CloseAsync(); } return(dishCategories); } catch (Exception) { throw new Exception("Problem getting dish categories"); } }
public async Task <DishCategory> GetDishCategory(int dishCategoryId, int userId) { try { var dishCategory = new DishCategory(); bool isDishExist = false; string selectCommandText = @"SELECT * FROM DishCategory WHERE UserId=@userId ANd DishCategoryId=@dishCategoryId"; SqlParameter user_id = new SqlParameter("@userId", SqlDbType.Int); user_id.Value = userId; SqlParameter dish_category_id = new SqlParameter("@dishCategoryId", SqlDbType.Int); dish_category_id.Value = dishCategoryId; using (SqlDataReader reader = await SqlHelper.ExecuteReaderAsync(conStr, selectCommandText, CommandType.Text, user_id, dish_category_id)) { while (reader.Read()) { isDishExist = true; dishCategory.Title = (string)reader["DishCategoryTitle"]; } await reader.CloseAsync(); } return(isDishExist ? dishCategory : null); } catch (System.Exception) { throw new Exception("Problem getting dish category"); } }
public async Task <bool> Update(int userId, int dishCategoryId, DishCategory dishCategory) { try { string updateCommandText = @"UPDATE DishCategory SET DishCategoryTitle = @dishCategoryTitle WHERE DishCategoryId = @dishCategoryId AND UserId = @userId"; SqlParameter dish_title = new SqlParameter("@dishcategoryTitle", dishCategory.Title); SqlParameter dish_category_id = new SqlParameter("@dishCategoryId", dishCategoryId); SqlParameter user_id = new SqlParameter("@userId", userId); Int32 rows = await SqlHelper.ExecuteNonQueryAsync(conStr, updateCommandText, CommandType.Text, dish_title, dish_category_id, user_id); if (rows >= 1) { return(true); } return(false); } catch (Exception) { throw new Exception("Error to update dish category"); } }
// PUT api/dishcategory/ public HttpResponseMessage Put([FromBody] DishCategory value, string filter = null) { ServerValidationInfo vi = null; value.UpdateDate = DateTime.Now; if (!ModelState.IsValid) { vi = new ServerValidationInfo(ModelState); } if (filter == null) { context.Entry(value).State = System.Data.EntityState.Modified; } else { var old = context.DishCategories.SingleOrDefault(queryBuider.CreateWhere(filter)); old.Id = value.Id; old.Code = value.Code; old.Name = value.Name; old.UpdateUserId = value.UpdateUserId; old.UpdateDate = value.UpdateDate; } if (vi != null && vi.ContainsError) { return(Request.CreateResponse(HttpStatusCode.BadRequest, vi)); } var result = context.SaveChanges() > 0; return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public async Task <Result <Guid> > HandleAsync(AddDishCategoryToRestaurantCommand command, User currentUser, CancellationToken cancellationToken = default) { if (command == null) { throw new ArgumentNullException(nameof(command)); } if (currentUser == null) { return(FailureResult <Guid> .Unauthorized()); } if (currentUser.Role < Role.RestaurantAdmin) { return(FailureResult <Guid> .Forbidden()); } var restaurant = await restaurantRepository.FindByRestaurantIdAsync(command.RestaurantId, cancellationToken); if (restaurant == null) { return(FailureResult <Guid> .Create(FailureResultCode.RestaurantDoesNotExist)); } if (currentUser.Role == Role.RestaurantAdmin && !restaurant.HasAdministrator(currentUser.Id)) { return(FailureResult <Guid> .Forbidden()); } var dishCategory = new DishCategory(new DishCategoryId(Guid.NewGuid()), command.RestaurantId, command.Name); await dishCategoryRepository.StoreAsync(dishCategory, cancellationToken); return(SuccessResult <Guid> .Create(dishCategory.Id.Value)); }
private DishCategory GetCategoryFromPicker(string category) { DishCategory categoryType = 0; switch (category) { case "Гарнир": categoryType = DishCategory.Garnish; break; case "Мясное": categoryType = DishCategory.Meat; break; case "Салат": categoryType = DishCategory.Salad; break; case "Хлеб": categoryType = DishCategory.Bread; break; default: throw new ArgumentOutOfRangeException(); } return(categoryType); }
public ActionResult Index(string act = "", int id = 0, int aId = 0, int storeId = 0, int pageIndex = 1, int pageSize = 20, string sortData = "") { //显示 if (string.IsNullOrEmpty(act)) { ViewModel <DishCategory> vm = new ViewModel <DishCategory>(); string filterSql = $"type = 2 and aid = {aId} and storeId = {storeId} and state<>-1"; vm.DataList = DishCategoryBLL.SingleModel.GetList(filterSql, pageSize, pageIndex, "*", "is_order desc"); vm.TotalCount = DishCategoryBLL.SingleModel.GetCount(filterSql); vm.PageIndex = pageIndex; vm.PageSize = pageSize; vm.aId = aId; vm.storeId = storeId; return(View(vm)); } else { //删除 if (act == "del") { if (id <= 0) { _result.code = 0; _result.msg = "参数错误"; } else { DishCategory updateModel = DishCategoryBLL.SingleModel.GetModel(id); if (updateModel != null) { updateModel.state = -1; bool updateResult = DishCategoryBLL.SingleModel.Update(updateModel); if (updateResult) { _result.code = 1; _result.msg = "删除成功"; } else { _result.code = 0; _result.msg = "删除失败"; } } else { _result.code = 0; _result.msg = "删除失败,分类不存在"; } } } else if (act == "sort") { bool updateResult = DishCategoryBLL.SingleModel.UpdateSortBatch(sortData); _result.code = updateResult ? 1 : 0; _result.msg = updateResult ? "修改成功" : "修改失败"; } } return(Json(_result)); }
public ActionResult DeleteConfirmed(int id) { DishCategory dishCategory = db.DishCategories.Find(id); db.DishCategories.Remove(dishCategory); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,Name,Image,IsDeleted,DateModification")] DishCategory dishCategory) { if (ModelState.IsValid) { DishCategoryService.Update(dishCategory.Id, dishCategory); return(RedirectToAction("Index")); } return(View(dishCategory)); }
public async Task <ActionResult> DeleteConfirmed(string id) { DishCategory dishCategory = await db.DishCategories.FindAsync(id); db.DishCategories.Remove(dishCategory); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public IActionResult Create([Bind("DishCategoryId,Name")] DishCategory dishCategory) { if (ModelState.IsValid) { _dishCategoryService.CreateDishCategory(dishCategory); return(RedirectToAction(nameof(Index))); } return(View(dishCategory)); }
public ActionResult Create() { var dishCategory = new DishCategory(); foreach (var culture in SupportedCulture.GetList()) dishCategory.DishCategories_Locale.Add(new DishCategory_Locale() { Culture = culture }); return View(dishCategory); }
public async Task AddDishCategory(DishCategory addDishCategory) { addDishCategory.Status = true; addDishCategory.IsAvailable = true; await _context.DishCategories.AddAsync(addDishCategory); await _context.SaveChangesAsync(); }
public ActionResult Edit([Bind(Include = "ID,Name")] DishCategory dishCategory) { if (ModelState.IsValid) { db.Entry(dishCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dishCategory)); }
/// <summary> /// Constructor to create a DishGroup list from an ObservableCollection of Dishes. /// </summary> /// <param name="cat"></param> /// <param name="dishes"></param> public DishGroup(DishCategory cat, ObservableCollection <Dish> dishes) { // initialize properties DishGroupCategory = cat; Clear(); foreach (Dish dish in dishes) { Add(dish); } }
private void AddInTreeRecipeName(DishCategory category, string name) { string c = category.ToString(); TreeNode[] nodes = treeView1.Nodes.Find(c, true); if (nodes.Length > 0) { nodes[0].Nodes.Add(name); } }
// GET: Menu/Create public ActionResult Create() { ViewBag.DishCategory = db.DishCategories.Include(d => d.Dishes).ToList(); DishCategory Granishlist = db.DishCategories.Include(d => d.Dishes).Where(c => c.Id == "ZdesDolzhenBitGarnir").FirstOrDefault(); ViewBag.Garnishes = Granishlist.Dishes.ToList(); var l = db.Packs.Include(c => c.Dishes).OrderByDescending(c => c.DateOfCreation).ToList(); ViewBag.Packs = l; return(View()); }
private void AddRecipe_Click(object sender, EventArgs e) { string name = NameText.Text; string desc = Description.Text; DishCategory cat = (DishCategory)Enum.Parse(typeof(DishCategory), CategoryChoose.Text); Recipe rec = new Recipe(name, cat, list); rec.Description = desc; Main.BOOK.recipes.Add(rec); this.Close(); }
public ActionResult Create([Bind(Include = "ID,Name")] DishCategory dishCategory) { if (ModelState.IsValid) { db.DishCategories.Add(dishCategory); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dishCategory)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name")] DishCategory dishCategory) { if (ModelState.IsValid) { db.Entry(dishCategory).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(dishCategory)); }
public async Task <IActionResult> Create([Bind("DishCategoryId,Description")] DishCategory dishCategory) { if (ModelState.IsValid) { _context.Add(dishCategory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(dishCategory)); }
public async Task <bool> Handle(AddMenuCategoryCommand request, CancellationToken cancellationToken) { var _newMenuCategory = new DishCategory { Category = request.MenuCategory.Category, }; dbContext.DishCategories.Add(_newMenuCategory); await dbContext.SaveChangesAsync(); return(true); }
public async Task <ActionResult> Create([Bind(Include = "Id,Name")] DishCategory dishCategory) { if (ModelState.IsValid) { db.DishCategories.Add(dishCategory); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(dishCategory)); }
// Convert the raw database data into an Dish object private Dish Read(DataRow dataRow) { int id = (int)dataRow["Id"]; string name = (string)dataRow["name"]; string description = dataRow["description"].ToString(); string ingredients = (string)dataRow["ingredients"]; double price = (double)dataRow["price"]; int stock = (int)dataRow["stock"]; DishCategory category = (DishCategory)int.Parse(dataRow["category"].ToString()); return(new Dish(id, name, description, ingredients, price, stock, category)); }
public ActionResult Edit(DishCategory dishCategory, IList<DishCategory_Locale> locales) { if (dishCategory == null) { TempData["Result"] = Resource.RecordNotFound; } else { dishCategory.Name = locales.First(l => l.Culture == SupportedCulture.En).DisplayName.Replace(" ", "-"); if (ModelState.IsValid) if (db.DishCategories.Any(dc => dc.Name == dishCategory.Name && dc.Id != dishCategory.Id)) ModelState.AddModelError("Unique", Resource.Unique); if (ModelState.IsValid) { foreach (var locale in locales) { db.DishCategory_Locale.Attach(locale); db.ObjectStateManager.ChangeObjectState(locale, EntityState.Modified); } db.DishCategories.Attach(dishCategory); db.ObjectStateManager.ChangeObjectState(dishCategory, EntityState.Modified); db.SaveChanges(); TempData["Result"] = Resource.ChangesSaved; } else { return Edit(dishCategory.Id); } } return RedirectToAction("Index"); }