public ActionResult Edit(CategoryStructureViewModel vm) { //var db = new ProductRepository(); vm.Category = _repository.GetCategory(vm.Category.Id); if (vm.Category == null) { ErrorFormat("User #{0} tries to update non-existing category #{1}!", User.Identity.Name, vm.Category.Id); return(RedirectToAction("notfound", "help")); } _repository.Save(vm.Category); SetTempOkMessage("Category {0} was successfully updated", vm.Category.Name); return(RedirectToAction("edit", new { id = vm.Category.Id })); }
public ActionResult DoSave(/*int id, */ CategoryStructureViewModel vm, CategoryStructure newItem) { try { //var db = new OnBalance.Models.CategoryStructureRepository(); //var dbProduct = new ProductRepository(); //Category model = dbProduct.GetCategory(id); //string newName = Request["NewName"]; //bool isNewApproved = false; //InfoFormat("User #{0} updates Category #{1} to name: {2}, status: {3} ({4}), organization: #{5}", User.Identity.Name, vm.Category.Id, vm.Category.Name, vm.Category.StatusName, vm.Category.StatusId, vm.Category.OrganizationId); //InfoFormat("User #{0} updates Category #{1} to name: {2}, status: {3} ({4}), organization: #{5}", User.Identity.Name, model.Id, model.Name, model.StatusName, model.StatusId, model.OrganizationId); _productRepository.Save(vm.Category); //UpdateModel<Category>(model, "Category__"); //dbProduct.SubmitChanges(); //if(CategoryStructure != null) //{ Info("Updating category structure..."); foreach (var item in vm.CategoryStructure) { InfoFormat(" Category structure: #{0, -8}. {1}", item.Id, item.FieldName); _repository.Update(item); } //} _repository.Add(newItem); /* * if(string.IsNullOrEmpty(newName) == false) * { * bool.TryParse(Request["NewStatus"], out isNewApproved); * CategoryStructure cs = new CategoryStructure(); * cs.FieldName = newName; * cs.StatusId = isNewApproved ? (byte)Status.Approved : (byte)Status.Deleted; * cs.CategoryId = vm.Category.Id; * db.Add(cs); * } */ _repository.SubmitChanges(); return(PartialView("CategoryStructure", vm.Category)); } catch (Exception ex) { Error("Error updating Category structure!", ex); throw ex; } }
public ActionResult Edit(int id) { CategoryStructureViewModel vm = new CategoryStructureViewModel(); //var model = new Category(); //var db = new ProductRepository(); vm.Category = _repository.GetCategory(id); if (vm.Category == null) { ErrorFormat("User #{0} tries to edit non-existing category #{1}!", User.Identity.Name, id); return(RedirectToAction("notfound", "help")); } //model.Organization = new OrganizationRepository().Items.Single(x => x.Id == model.Category.id); return(View(vm)); }
// // POST: /pradmin/dosavestructure //[HttpPost] public ActionResult DoSaveStructure(int id, CategoryStructureViewModel vm /*FormCollection f, List<CategoryStructure> CategoryStructure*/) { try { var db = new OnBalance.Domain.Entities.CategoryStructureRepository(); var dbProduct = new ProductRepository(); //Category model = dbProduct.GetCategory(id); string newName = Request["NewName"]; bool isNewApproved = false; //InfoFormat("User #{0} updates Category #{1} to name: {2}, status: {3} ({4}), organization: #{5}", User.Identity.Name, vm.Category.Id, vm.Category.Name, vm.Category.StatusName, vm.Category.StatusId, vm.Category.OrganizationId); //InfoFormat("User #{0} updates Category #{1} to name: {2}, status: {3} ({4}), organization: #{5}", User.Identity.Name, model.Id, model.Name, model.StatusName, model.StatusId, model.OrganizationId); throw new NotImplementedException("dbProduct.Save(vm.Category)"); //dbProduct.Save(vm.Category); //UpdateModel<Category>(model, "Category__"); //dbProduct.SubmitChanges(); //if(CategoryStructure != null) //{ Info("Updating category structure..."); foreach (var item in vm.CategoryStructure) { InfoFormat(" Category structure: #{0, -8}. {1}", item.Id, item.FieldName); throw new NotImplementedException("db.Update(item)"); //db.Update(item); } //} if (string.IsNullOrEmpty(newName) == false) { bool.TryParse(Request["NewStatus"], out isNewApproved); OnBalance.Domain.Entities.CategoryStructure cs = new OnBalance.Domain.Entities.CategoryStructure(); cs.FieldName = newName; cs.StatusId = isNewApproved ? (byte)Status.Approved : (byte)Status.Deleted; cs.CategoryId = vm.Category.Id; db.Add(cs); } db.SubmitChanges(); return(PartialView("CategoryStructure", vm.Category)); } catch (Exception ex) { Error("Error updating Category structure!", ex); throw ex; } }