private string UploadedFile(BoutiqViewModel model) { string uniqueFileName = null; if (model.itemImage != null) { string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.itemImage.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { model.itemImage.CopyTo(fileStream); } } return(uniqueFileName); }
public async Task <IActionResult> New(BoutiqViewModel model) { DateTime localDat = DateTime.Now; totalValue.Add(model.SalePrice); BoutiqWorths = totalValue.Sum(); ViewBag.Title = "Put your page title here"; var localDate = localDat.ToString("dd-MMM-yyyy hh:mm:ss"); if (ModelState.IsValid) { string uniqueFileName = UploadedFile(model); string iDate = model.DateOfSale; DateTime oDate = Convert.ToDateTime(iDate); Boutiq botiq = new Boutiq { Type = model.Type, Description = model.Description, Cost = model.Cost, itemImage = uniqueFileName, status = model.status, DateOfEntry = localDate, SalePrice = model.SalePrice, DateOfSale = oDate, BoutiqWorth = BoutiqWorths }; dbContext.Add(botiq); await dbContext.SaveChangesAsync(); if (botiq.status == "deposited") { return(RedirectToAction(nameof(GetAllDeposited))); } else if (botiq.status == "sold") { return(RedirectToAction(nameof(GetSoldStalk))); } return(RedirectToAction(nameof(GetCurrentStalk))); } return(View()); }