public ActionResult Insert(UserFormViewModel formViewModel) { // if given data is not valid, send back the object with error message if (!ModelState.IsValid) { var cities = _cityRepo.GetAll().OrderBy(c => c.Name); var areas = _areaRepo.GetAreasByCityId(formViewModel.User.CityId).OrderBy(a => a.Name); formViewModel.Cities = cities; formViewModel.Areas = areas; return(View("Add", formViewModel)); } // first letter of every word is capital formViewModel.User.FirstName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(formViewModel.User.FirstName.ToLower()); formViewModel.User.LastName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(formViewModel.User.LastName.ToLower()); // update in db _userRepo.Insert(formViewModel.User); // if consumer if (formViewModel.User.UserType == UserType.Consumer) { HomeController.LoggedUser = formViewModel.User; return(RedirectToAction("index", "user")); } // if employee else if (formViewModel.User.UserType == UserType.Employee) { return(RedirectToAction("employees", "user")); } // if labour else { return(RedirectToAction("labours", "user")); } }
public ActionResult Edit(int id) { var client = clientRepository.Get(id); var userLogin = userLoginRepository.Get(id); var cities = cityRepository.GetAll().OrderBy(c => c.Name); var areas = areaRepository.GetAreasByCityId(client.CityId).OrderBy(a => a.Name); if (client == null) { return(HttpNotFound()); } var viewModel = new ClientFormViewModel { Client = client, UserLogin = userLogin, Cities = cities, Areas = areas }; return(View(viewModel)); }
public ActionResult Edit(int id) { var labour = labourRepository.Get(id); var userLogin = userLoginRepository.Get(id); var cities = cityRepository.GetAll().OrderBy(c => c.Name); var areas = areaRepository.GetAreasByCityId(labour.CityId).OrderBy(c => c.Name); var services = serviceRepository.GetAll().OrderBy(s => s.ServiceName); if (labour == null) { return(HttpNotFound()); } var viewModel = new LabourFormViewModel { Labour = labour, UserLogin = userLogin, Cities = cities, Areas = areas, Services = services }; return(View(viewModel)); }
/*City-Area*/ public JsonResult AreaList(int id) { var area = areaRepository.GetAreasByCityId(id).OrderBy(a => a.Name).ToList(); return(Json(new SelectList(area.ToArray(), "Id", "Name"), JsonRequestBehavior.AllowGet)); }