/// <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; } }
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; } }