public ActionResult Create([Bind(Include = "Id,ManagerName")] ManagerViewModel managerViewModel) { if (string.IsNullOrEmpty(managerViewModel.ManagerName)) { ModelState.AddModelError("ManagerName", "Ваедите имя менеджера"); } else if (managerViewModel.ManagerName.Length < 3) { ModelState.AddModelError("ManagerName", "Недопустимая длина строки"); } if (ModelState.IsValid) { try { Mapper.Initialize(cfg => cfg.CreateMap <ManagerViewModel, ManagerDTO>()); var manager = Mapper.Map <ManagerViewModel, ManagerDTO>(managerViewModel); _managerService.AddManager(manager); return(RedirectToAction("Index")); } catch (ValidationException ex) { ModelState.AddModelError(ex.Property, ex.Message); } } return(View(managerViewModel)); }
public IActionResult Create(Manager man) { if (ModelState.IsValid) { _managerService.AddManager(man); return(RedirectToAction(nameof(Index))); } return(View(man)); }
public void SendManagerInfo(ManagerModel manager) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <ManagerModel, ManagerDTO>(); }); IMapper mapper = config.CreateMapper(); db.AddManager(mapper.Map <ManagerModel, ManagerDTO>(manager)); }
public IActionResult AddManager(ManagerResource newManager) { try { _managerService.AddManager(_mapper.ParseManager(newManager)); _managerService.SaveChanges(); return(CreatedAtAction("AddCustomer", newManager)); } catch (Exception) { return(BadRequest()); } }
public IActionResult AddManager(ManagerDTO newManager) { try { var receivedManager = _mapper.Map <Manager>(newManager); _managerService.AddManager(receivedManager); return(CreatedAtAction("AddManager", receivedManager)); } catch (Exception) { // TODO: Check if this is the right error code for this. return(StatusCode(500)); } }
public IActionResult Post(ManagerViewModel managerViewModel) { try { var manager = _mapper.Map <ManagerModel>(managerViewModel); _managerService.AddManager(manager); } catch (Exception ex) { return(new BadRequestObjectResult(new { Message = ex.Message })); } return(Ok(new { Message = "Manager created successfully" })); }
public IActionResult Create(Manager manager) { ManagerValidation val = new ManagerValidation(_managerService); ValidationResult model = val.Validate(manager); if (model.IsValid) { _managerService.AddManager(manager); return(RedirectToAction(nameof(Index))); } else { foreach (ValidationFailure _error in model.Errors) { ModelState.AddModelError(_error.PropertyName, _error.ErrorMessage); } } return(View(manager)); }
private void SaveExecute(object parameter) { try { DateTime dateOfBirth; if (!ValidationClass.JMBGisValid(User.JMBG, out dateOfBirth)) { MessageBox.Show("JMBG is not valid"); return; } int age = ValidationClass.CountAge(dateOfBirth); if (age < 18) { string str1 = string.Format("JMBG is not valid\nManager has to be at least 18 years old"); MessageBox.Show(str1); return; } tblUser userInDb = userService.GetUserByUserName(User.Username); if (userInDb != null) { string str1 = string.Format("User with this username exists\n" + "Enter another username"); MessageBox.Show(str1); return; } userInDb = userService.GetUserByJMBG(User.JMBG); if (userInDb != null) { string str1 = string.Format("User with this JMBG exists\n" + "Enter another JMBG"); MessageBox.Show(str1); return; } if (!ValidationClass.IsValidEmail(Manager.Email)) { MessageBox.Show("Email is not valid"); return; } tblManager managerInDb = managerService.GetManagerByEmail(Manager.Email); if (managerInDb != null) { string str1 = string.Format("Manager with this email exists\n" + "Enter another email"); MessageBox.Show(str1); return; } var passwordBox = parameter as PasswordBox; var password = passwordBox.Password; string encryptedString = EncryptionHelper.Encrypt(password); User.Gender = Gender; User.MaritalStatus = MartialStatus; User.Password = encryptedString; User = userService.AddUser(User); string reservePassword = string.Format("{0}WPF", Manager.ReservePassword); Manager.ReservePassword = reservePassword; Manager.UserID = User.UserID; managerService.AddManager(Manager); string str = string.Format("You registered as manager"); MessageBox.Show(str); view.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public JsonResult AddManager(string ManagerName) { int id = _managerService.AddManager(ManagerName); return(Json(id)); }