public IActionResult Create() { List <SelectListItem> useListItems = _userManager.GetAll().Select(c => new SelectListItem() { Value = c.id.ToString(), Text = c.Type }).ToList(); var model = new ViewModel_Customer(); model.UserTypeList = useListItems; return(View(model)); }
public IActionResult Edit(int id) { List <SelectListItem> userTypeList = _userManager.GetAll().Select(c => new SelectListItem() { Value = c.id.ToString(), Text = c.Type }).ToList(); var model = new ViewModel_Customer(); model = _mapper.Map <ViewModel_Customer>(_customerManager.GetById(id)); model.UserTypeList = userTypeList; //var model = _mapper.Map<IEnumerable<ViewModel_Customer>>(customerInfo); return(View(model)); }
public IActionResult Create(ViewModel_Customer model) { try { if (ModelState.IsValid) { string uniqueFileName = null; if (model.PhotoFile != null) { string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid() + "_" + model.PhotoFile.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); model.PhotoFile.CopyTo(new FileStream(filePath, FileMode.Create)); } Customer customer = new Customer() { CustomerName = model.CustomerName, Address = model.Address, ContactNo = model.ContactNo, Photo = uniqueFileName, UserType = model.UserType }; bool isAdded = _customerManager.Add(customer); { return(RedirectToAction("Details", new { id = customer.Id })); } } return(View()); } catch { return(View()); } }