public ActionResult Create(LotCreateModel model) { if (ModelState.IsValid) { try { LotDTO lot = Mapper.Map <LotDTO>(model); lotService.Create(User.Identity.GetUserId(), Mapper.Map <LotDTO>(model)); ModelState.Clear(); } catch (ItemNotExistInDbException) { return(new HttpStatusCodeResult(400, "Account was removed")); } } return(View(model)); }
public ActionResult Create(CreateLotModel model, IEnumerable <HttpPostedFileBase> files) { if (!ModelState.IsValid) { return(View(model)); } if (model.Tags != null) { model.Tags = model.Tags.Trim(); } var result = new LotViewModel(); using (var img = Image.FromStream(model.Picture.InputStream)) { result.Picture = ImageHelper.ImageToByteArray(img); } result.Name = model.Name; result.Description = model.Description; var user = userService.GetOneByPredicate(u => u.Name == User.Identity.Name); if (user != null) { result.ProfileId = user.ProfileId; } result.StartDate = DateTime.Now; result.EndDate = result.StartDate + TimeSpan.FromDays(model.Days); var tags = model.Tags != null?model.Tags.Split(' ') : new string[0]; result.Tags = new List <TagViewModel>(); foreach (var tag in tags) { result.Tags.Add(new TagViewModel { Name = tag }); } lotService.Create(result.ToLotEntity()); return(RedirectToAction("Index", "Home")); }