public IActionResult Create(SliderViewModel model) { if (model == null) { return(NotFound()); } if (ModelState.IsValid) { var slider = _mapper.Map <SliderViewModel, SliderItem>(model); slider.AddedBy = _admin.Fullname; slider.AddedDate = DateTime.Now; if (model.File != null) { slider.Image = _fileManager.Upload(model.File); } else { slider.Image = null; } _context.Add(slider); _context.SaveChanges(); return(RedirectToAction("index")); } return(View(model)); }
public IActionResult Create(LabelAViewModel model) { if (ModelState.IsValid) { var label = _mapper.Map <LabelAViewModel, Label>(model); label.AddedBy = _admin.Fullname; label.AddedDate = DateTime.Now; _context.Add(label); _context.SaveChanges(); return(RedirectToAction("index")); } return(Ok(model)); }
public IActionResult Create(ApostViewModel model) { if (model == null) { return(NotFound()); } if (ModelState.IsValid) { var post = _mapper.Map <ApostViewModel, Post>(model); post.AddedBy = _admin.Fullname; post.AddedDate = DateTime.Now; if (model.LabelId == 0) { post.LabelId = null; } if (model.File != null) { post.Image = _fileManager.Upload(model.File); } else { post.Image = null; } post.WriterId = model.WriterId; _context.Add(post); _context.SaveChanges(); return(RedirectToAction("index")); } return(View(model)); }