public IHttpActionResult Get(int id) { try { // get log.Debug("_energySourceService.GetEnergySource - energySourceId: " + id + " "); var energySource = new EnergySourceViewModel(_energySourceService.GetEnergySource(id)); log.Debug("_energySourceService.GetEnergySource - " + EnergySourceViewModel.FormatEnergySourceViewModel(energySource)); log.Debug("result: 'success'"); //return Json(energySource, JsonRequestBehavior.AllowGet); //return Content(JsonConvert.SerializeObject(energySource), "application/json"); //return energySource; //return JsonConvert.SerializeObject(energySource); return(Ok(energySource)); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
private EnergySourceDTO Create(EnergySourceViewModel viewModel) { try { log.Debug(EnergySourceViewModel.FormatEnergySourceViewModel(viewModel)); EnergySourceDTO energySource = new EnergySourceDTO(); // copy values viewModel.UpdateDTO(energySource, null); //RequestContext.Principal.Identity.GetUserId()); // audit energySource.CreateBy = null; //RequestContext.Principal.Identity.GetUserId(); energySource.CreateOn = DateTime.UtcNow; // add log.Debug("_energySourceService.AddEnergySource - " + EnergySourceDTO.FormatEnergySourceDTO(energySource)); int id = _energySourceService.AddEnergySource(energySource); energySource.EnergySourceId = id; log.Debug("result: 'success', id: " + id); return(energySource); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
//[ValidateAntiForgeryToken] public IHttpActionResult Upsert(EnergySourceViewModel viewModel) { log.Debug("Upsert"); if (viewModel.EnergySourceId > 0) { var t = Update(viewModel); //return Json(true); //return JsonConvert.SerializeObject(t.EnergySourceId); return(Ok(t.EnergySourceId)); } else { var t = Create(viewModel); //return Json(t.EnergySourceId); //return JsonConvert.SerializeObject(t.EnergySourceId); return(Ok(t.EnergySourceId)); } }
private EnergySourceDTO Update(EnergySourceViewModel viewModel) { try { log.Debug(EnergySourceViewModel.FormatEnergySourceViewModel(viewModel)); // get log.Debug("_energySourceService.GetEnergySource - energySourceId: " + viewModel.EnergySourceId + " "); var existingEnergySource = _energySourceService.GetEnergySource(viewModel.EnergySourceId); log.Debug("_energySourceService.GetEnergySource - " + EnergySourceDTO.FormatEnergySourceDTO(existingEnergySource)); if (existingEnergySource != null) { // copy values viewModel.UpdateDTO(existingEnergySource, null); //RequestContext.Principal.Identity.GetUserId()); // update log.Debug("_energySourceService.UpdateEnergySource - " + EnergySourceDTO.FormatEnergySourceDTO(existingEnergySource)); _energySourceService.UpdateEnergySource(existingEnergySource); log.Debug("result: 'success'"); } else { log.Error("existingEnergySource: null, EnergySourceId: " + viewModel.EnergySourceId); } return(existingEnergySource); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
//[ValidateAntiForgeryToken] public IHttpActionResult SaveList(EnergySourceViewModel[] viewModels, int?id) { try { log.Debug("SaveList"); if (viewModels != null) { // save list foreach (EnergySourceViewModel viewModel in viewModels) { log.Debug(EnergySourceViewModel.FormatEnergySourceViewModel(viewModel)); if (viewModel.EnergySourceId > 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; } }