private void SaveCostume(CostumeViewModel costume) { if (string.IsNullOrEmpty(costume.Name)) { throw new ArgumentException("Costume name cannot be empty!", "costume"); } if (costume.Id == 0) { costume.ImageFileName = costume.ImageFileName ?? string.Empty; var costumeEntity = Mapper.Map <Costume>(costume); _context.Costumes.Add(costumeEntity); } else { var costumeEntity = _context.Costumes .Include(e => e.AgeRanges) .Include(e => e.HairColors) .Include(e => e.HairLengths) .Include(e => e.Sources) .Single(e => e.CostumeId == costume.Id); Mapper.Map(costume, costumeEntity); } Save(); }
public void SaveCostume(CostumeViewModel costume, HttpPostedFileBase imageFile, HttpServerUtilityBase server) { if (imageFile != null && imageFile.ContentLength > 0) { string fileName = UploadFile(imageFile, costume.Name, server); costume.ImageFileName = fileName; } SaveCostume(costume); }
public ActionResult EditCostume(CostumeViewModel costume, HttpPostedFileBase imageFile) { if (costume != null && ModelState.IsValid) { _costumeService.SaveCostume(costume, imageFile, Server); TempData[AdminMessageKey] = string.Format("{0} costume saved!", costume.Name); return(RedirectToAction("Admin")); } ModelState.AddModelError("name", "Each costume must have a name!"); return(RedirectToAction("EditCostume")); }