public IActionResult Create() { ViewBag.productcuisine = _productcuisinemasterservices.GetAll().ToList(); var model = new MenumasterCreateViewModel(); return(View(model)); }
public async Task <IActionResult> Create(MenumasterCreateViewModel model) { if (ModelState.IsValid) { //ApplicationUser usr = await GetCurrentUserAsync(); //var id = usr.Id; var store = new menumaster { id = model.id , name = model.name // , profilephoto=model.profilephoto , isdeleted = false , isactive = false, productcuisineid = model.productcuisineid }; 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); FileStream fs = new FileStream(path, FileMode.Create); await model.img.CopyToAsync(fs); fs.Close(); store.img = '/' + uploadDir + '/' + fileName; } await _menumasterservices.CreateAsync(store); TempData["success"] = "Record Save successfully"; return(RedirectToAction(nameof(test))); } else { return(View()); } }