public async Task <IActionResult> Create() { //ApplicationUser usr = await GetCurrentUserAsync(); //var id = usr.Id; ViewBag.productcuisine = _productcuisinemasterservices.GetAll().ToList(); var model = new productCreateViewModel(); return(View(model)); }
public async Task <IActionResult> Create(productCreateViewModel model) { if (ModelState.IsValid) { ApplicationUser usr = await GetCurrentUserAsync(); var id = usr.Id; var store = new product { //id, productcuisineid, name, img, foodtype, amount, description, discounttype, discountamount, //createddate, isdeleted, isactive, storeid id = model.id, productcuisineid = model.productcuisineid, name = model.fkmenuid.ToString(), fkmenuid = model.fkmenuid, foodtype = model.foodtype, amount = model.amount, description = model.description, discounttype = model.discounttype, discountamount = model.discountamount, createddate = model.createddate , isdeleted = false , isactive = false , storeid = id , status = model.status }; if (model.img != null && model.img.Length > 0) { var uploadDir = @"uploads/product"; var fileName = Path.GetFileNameWithoutExtension(model.img.FileName); var extesion = Path.GetExtension(model.img.FileName); var webRootPath = _hostingEnvironment.WebRootPath; fileName = DateTime.UtcNow.ToString("yymmssfff") + fileName + extesion; var path = Path.Combine(webRootPath, uploadDir, fileName); await model.img.CopyToAsync(new FileStream(path, FileMode.Create)); store.img = '/' + uploadDir + '/' + fileName; } await _productservices.CreateAsync(store); return(RedirectToAction(nameof(Index))); } else { return(View()); } }