public ActionResult Create() { ViewBag.DropDownList = ReUzze.Helpers.EnumHelper.SelectListFor<Condition>(); var model = new ReUzze.Models.EntityViewModel(); PutTypeDropDownInto(model); return View(model); }
public ActionResult Create(ReUzze.Models.EntityViewModel viewModel) { try { if (!ModelState.IsValid) return View(viewModel); if (viewModel.SelectedCategoryId == null) { ViewBag.DropDownList = ReUzze.Helpers.EnumHelper.SelectListFor<Condition>(); var model = new ReUzze.Models.EntityViewModel() { StatusMessage = "You need to select a category!", Categories = new SelectList(this.UnitOfWork.CategoryRepository.Get(), "Id", "Name") }; PutTypeDropDownInto(model); return View(model); } User usr = this.UnitOfWork.UserRepository.Get().Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); var entity = new Entity(); entity.Title = viewModel.Title; entity.Description = viewModel.Description; entity.StartTime = viewModel.StartTime; entity.EndTime = viewModel.EndTime; entity.InstantSellingPrice = viewModel.InstantSellingPrice; if (viewModel.Condition.GetValueOrDefault().ToString() == "Used") { entity.Condition = Condition.Used; } else { entity.Condition = Condition.New; } entity.UserId = usr.Id; entity.RegionId = usr.Person.Address.RegionId; entity.CategoryId = Convert.ToInt16(viewModel.SelectedCategoryId); this.UnitOfWork.EntityRepository.Insert(entity); this.UnitOfWork.Save(); // SAVE THE IMGES if (viewModel.Files.FirstOrDefault() != null) { foreach (var file in viewModel.Files) { if (file.ContentLength > 0) { repository.AddMedia(entity.Id, Path.GetFileName(file.FileName), file.ContentType); var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Resources/uploads"), fileName); file.SaveAs(path); } } } return RedirectToAction("Index", "Entity"); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } return RedirectToAction("Create", "Entity"); }
public ActionResult Edit(Int64 id) { var entity = repository.GetEntity(id); if (entity == null) throw new Exception(); var model = new ReUzze.Models.EntityViewModel { Title = entity.entity_title, Description = entity.entity_description, StartTime = entity.entity_starttime, EndTime = entity.entity_endtime, InstantSellingPrice = entity.entity_instantsellingprice, ShippingPrice = entity.entity_shippingprice }; return View(model); }