public ActionResult CreateGift(CreateGiftViewModel createGiftViewModel) { if (ModelState.IsValid) { var file = Request.Files["file"]; var logoPath = ""; if (file != null && file.ContentLength > 0) { logoPath = Guid.NewGuid() + Path.GetExtension(file.FileName); var path = Path.Combine(Server.MapPath(StringResources.GiftsLogoPath), logoPath); file.SaveAs(path); } else { logoPath = StringResources.NoGiftLogoPath; } createGiftViewModel.Logo = StringResources.GiftsLogoPath + logoPath; var newGift = Mapper.Map <DomainGift>(createGiftViewModel); _giftService.Create(newGift); return(RedirectToAction("CreateGiftSuccess")); } ModelState.AddModelError("", "Invalid model"); return(View()); }
private static string UploadImageGift(CreateGiftViewModel model) { var uploadFolder = Path.Combine(_appEnvironment.ContentRootPath + "\\wwwroot\\img\\wheel"); var uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Image.FileName; var path = Path.Combine(uploadFolder, uniqueFileName); var fileStream = new FileStream(path, FileMode.Create); model.Image.CopyTo(fileStream); fileStream.Close(); return(uniqueFileName); }
public IActionResult Create(CreateGiftViewModel vm) { var user = GetCurrentUserAsync().Result; Gift gift = new Gift() { Name = vm.Name, Price = vm.Price, PhotoPath = vm.PhotoPath, UserId = user.Id }; _giftRepo.Create(gift); return(RedirectToAction("Index", "Admin")); }