public IHttpActionResult Get(int id) { try { // get log.Debug("_partnerService.GetPartner - partnerId: " + id + " "); var partner = new PartnerViewModel(_partnerService.GetPartner(id)); log.Debug("_partnerService.GetPartner - " + PartnerViewModel.FormatPartnerViewModel(partner)); log.Debug("result: 'success'"); //return Json(partner, JsonRequestBehavior.AllowGet); //return Content(JsonConvert.SerializeObject(partner), "application/json"); //return partner; //return JsonConvert.SerializeObject(partner); return(Ok(partner)); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
private PartnerDTO Create(PartnerViewModel viewModel) { try { log.Debug(PartnerViewModel.FormatPartnerViewModel(viewModel)); PartnerDTO partner = new PartnerDTO(); // copy values viewModel.UpdateDTO(partner, null); //RequestContext.Principal.Identity.GetUserId()); // audit partner.CreateBy = null; //RequestContext.Principal.Identity.GetUserId(); partner.CreateOn = DateTime.UtcNow; // add log.Debug("_partnerService.AddPartner - " + PartnerDTO.FormatPartnerDTO(partner)); int id = _partnerService.AddPartner(partner); partner.PartnerId = id; log.Debug("result: 'success', id: " + id); return(partner); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
private PartnerDTO Update(PartnerViewModel viewModel) { try { log.Debug(PartnerViewModel.FormatPartnerViewModel(viewModel)); // get log.Debug("_partnerService.GetPartner - partnerId: " + viewModel.PartnerId + " "); var existingPartner = _partnerService.GetPartner(viewModel.PartnerId); log.Debug("_partnerService.GetPartner - " + PartnerDTO.FormatPartnerDTO(existingPartner)); if (existingPartner != null) { // copy values viewModel.UpdateDTO(existingPartner, null); //RequestContext.Principal.Identity.GetUserId()); // update log.Debug("_partnerService.UpdatePartner - " + PartnerDTO.FormatPartnerDTO(existingPartner)); _partnerService.UpdatePartner(existingPartner); log.Debug("result: 'success'"); } else { log.Error("existingPartner: null, PartnerId: " + viewModel.PartnerId); } return(existingPartner); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
//[ValidateAntiForgeryToken] public IHttpActionResult SaveList(PartnerViewModel[] viewModels, int?id) { try { log.Debug("SaveList"); if (viewModels != null) { // save list foreach (PartnerViewModel viewModel in viewModels) { log.Debug(PartnerViewModel.FormatPartnerViewModel(viewModel)); if (viewModel.PartnerId > 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; } }