private async void btnSave_Click(object sender, EventArgs e) { try { if (txtName.IsNotNullOrEmpty()) { MessageBoxUtil.MessageError(this, AlertMessages.MISSING_DATA); errorIcon.SetError(txtName, AlertMessages.ENTER_A_NAME); } else { if (isNew) { await personTypeService.AddAsync( new PersonType { Name = txtName.Text, Description = txtDescription.Text, CreatedDate = DateTime.Now, CreatedBy = Program.CurrentUser.UserName }); MessageBoxUtil.MessageOk(this, AlertMessages.INSERTED_SUCCESSFULLY); } else { var entity = await personTypeService.GetByIdAsync(int.Parse(txtIdPersonType.Text)); var Model = new PersonTypeViewModel { Id = int.Parse(txtIdPersonType.Text), Name = txtName.Text, Description = txtDescription.Text, CreatedDate = entity.CreatedDate, ModifiedDate = DateTime.Now, CreatedBy = Program.CurrentUser.UserName }; entity = mapper.Map(Model, entity); await personTypeService.UpdateAsync(entity); MessageBoxUtil.MessageOk(this, AlertMessages.UPDATED_SUCCESSFULLY); } this.isNew = false; this.isEdit = false; this.EnableBottons(); this.ClearTextBox(); this.LoadPersonTypes(); } } catch (Exception ex) { MessageBoxUtil.MessageError(this, ex.Message); } }
public async Task <IActionResult> Details(int id) { var returnUrl = Request.Headers["Referer"].ToString(); var personType = await _personTypeRepo.GetPersonType(id); PersonTypeViewModel personTypeVM = PersonTypeViewModelFactory.Details(personType, returnUrl); return(View("Edit", personTypeVM)); }
public async Task <IActionResult> Delete(PersonTypeViewModel personTypeVM) { await _personTypeRepo.DeletePersonType(personTypeVM.PersonType); TempData["message"] = "Your data has been deleted successfully."; TempData["toasterType"] = ToasterType.success; //return RedirectToAction(nameof(Index)); return(Redirect(personTypeVM.ReturnUrl)); }
public async Task <IActionResult> Edit(int id, string returnUrl = null) { if (String.IsNullOrEmpty(returnUrl)) { returnUrl = Request.Headers["Referer"].ToString(); } var personType = await _personTypeRepo.GetPersonType(id); PersonTypeViewModel personTypeVM = PersonTypeViewModelFactory.Edit(personType, returnUrl); return(View("Edit", personTypeVM)); }
public async Task <IActionResult> Edit([FromForm] PersonTypeViewModel personTypeVM) { if (ModelState.IsValid) { await _personTypeRepo.UpdatePersonType(personTypeVM.PersonType); TempData["message"] = "Your data has been updated successfully."; TempData["toasterType"] = ToasterType.success; return(RedirectToAction(nameof(Edit), new { id = personTypeVM.PersonType.Id, returnUrl = personTypeVM.ReturnUrl })); } else { TempData["message"] = "A problem has been ocurred while updating your data."; TempData["toasterType"] = ToasterType.info; } return(View("Edit", PersonTypeViewModelFactory.Edit(personTypeVM.PersonType, personTypeVM.ReturnUrl))); }
public async Task <IActionResult> Create([FromForm] PersonTypeViewModel personTypeVM) { if (ModelState.IsValid) { var newPersonType = await _personTypeRepo.AddPersonType(personTypeVM.PersonType); TempData["message"] = "Your data has been submitted successfully."; TempData["toasterType"] = ToasterType.success; //return RedirectToAction(nameof(Index)); return(RedirectToAction(nameof(Edit), new { id = newPersonType.Id, returnUrl = personTypeVM.ReturnUrl })); } TempData["message"] = "A problem has been ocurred while submitting your data."; TempData["toasterType"] = ToasterType.info; return(View("Edit", PersonTypeViewModelFactory.Create(personTypeVM.PersonType, personTypeVM.ReturnUrl))); }
public ActionResult Create(PersonTypeViewModel personTypeViewModel) { try { PersonType personType = new PersonType(); personType.PersonTypeName = personTypeViewModel.PersonTypeName; using (var dbModel = new OneSmallStepContext()) { dbModel.PersonType.Add(personType); dbModel.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }