public ActionResult Create(ParishViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var parish = _mapper.Map <Parish>(model); var IsSuccess = _repo.Create(parish); if (!IsSuccess) { ModelState.AddModelError("", "Sorry, Something went wrong..."); return(View(model)); } return(RedirectToAction(nameof(Index))); } catch (Exception) { ModelState.AddModelError("", "Sorry, Something went wrong..."); return(View()); } }
/// <summary> /// Get Parish by id /// </summary> /// <param name="id">Parish id</param> /// <returns>Parish json view model</returns> public IHttpActionResult Get(int id) { try { // get log.Debug("_parishService.GetParish - parishId: " + id + " "); var parish = new ParishViewModel(_parishService.GetParish(id)); log.Debug("_parishService.GetParish - " + ParishViewModel.FormatParishViewModel(parish)); log.Debug("result: 'success'"); //return Json(parish, JsonRequestBehavior.AllowGet); //return Content(JsonConvert.SerializeObject(parish), "application/json"); //return parish; //return JsonConvert.SerializeObject(parish); return(Ok(parish)); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
private ParishDTO Create(ParishViewModel viewModel) { try { log.Debug(ParishViewModel.FormatParishViewModel(viewModel)); ParishDTO parish = new ParishDTO(); // copy values viewModel.UpdateDTO(parish, null); //RequestContext.Principal.Identity.GetUserId()); // audit parish.CreateBy = null; //RequestContext.Principal.Identity.GetUserId(); parish.CreateOn = DateTime.UtcNow; // add log.Debug("_parishService.AddParish - " + ParishDTO.FormatParishDTO(parish)); int id = _parishService.AddParish(parish); parish.ParishId = id; log.Debug("result: 'success', id: " + id); return(parish); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
public async ValueTask <IActionResult> Post([FromBody] ParishViewModel model) { if (ModelState.IsValid) { Parish parish = model.Convert <ParishViewModel, Parish>(_mapper); (bool succeeded, Parish addedParish, string error) = await _repo.Add(parish); if (succeeded) { return(await Get(addedParish.Id)); } return(BadRequest(new { Message = error })); } return(BadRequest(new { Errors = ModelState.Values.SelectMany(e => e.Errors).ToList() })); }
//[ValidateAntiForgeryToken] /// <summary> /// Updates data for an existing Parish, or creates a new Parish if the Id is 0 /// </summary> /// <param name="viewModel">Parish data</param> /// <returns>Parish id</returns> public IHttpActionResult Upsert(ParishViewModel viewModel) { log.Debug("Upsert"); if (viewModel.ParishId > 0) { var t = Update(viewModel); //return Json(true); //return JsonConvert.SerializeObject(t.ParishId); return(Ok(t.ParishId)); } else { var t = Create(viewModel); //return Json(t.ParishId); //return JsonConvert.SerializeObject(t.ParishId); return(Ok(t.ParishId)); } }
public ActionResult Delete(int id, ParishViewModel model) { try { var parish = _repo.FindById(id); if (parish == null) { return(NotFound()); } var IsSuccess = _repo.Delete(parish); if (!IsSuccess) { return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { return(View(model)); } }
private ParishDTO Update(ParishViewModel viewModel) { try { log.Debug(ParishViewModel.FormatParishViewModel(viewModel)); // get log.Debug("_parishService.GetParish - parishId: " + viewModel.ParishId + " "); var existingParish = _parishService.GetParish(viewModel.ParishId); log.Debug("_parishService.GetParish - " + ParishDTO.FormatParishDTO(existingParish)); if (existingParish != null) { // copy values viewModel.UpdateDTO(existingParish, null); //RequestContext.Principal.Identity.GetUserId()); // update log.Debug("_parishService.UpdateParish - " + ParishDTO.FormatParishDTO(existingParish)); _parishService.UpdateParish(existingParish); log.Debug("result: 'success'"); } else { log.Error("existingParish: null, ParishId: " + viewModel.ParishId); } return(existingParish); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
//[ValidateAntiForgeryToken] /// <summary> /// Save a list of Parish /// </summary> /// <param name="viewModels">Parish view models</param> /// <param name="id">(not used)</param> /// <returns>true if the operation is successfull</returns> public IHttpActionResult SaveList(ParishViewModel[] viewModels, int?id) { try { log.Debug("SaveList"); if (viewModels != null) { // save list foreach (ParishViewModel viewModel in viewModels) { log.Debug(ParishViewModel.FormatParishViewModel(viewModel)); if (viewModel.ParishId > 0) { var t = Update(viewModel); } else { var t = Create(viewModel); } } } else { log.Error("viewModels: null"); } //return Json(true); //return JsonConvert.SerializeObject(true); return(Ok(true)); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
public ParishViewPage(Parish parish) { InitializeComponent(); BindingContext = viewModel = new ParishViewModel(parish); }