コード例 #1
0
        public IHttpActionResult Get(int id)
        {
            try
            {
                // get
                log.Debug("_contributionTypeService.GetContributionType - contributionTypeId: " + id + " ");

                var contributionType = new ContributionTypeViewModel(_contributionTypeService.GetContributionType(id));

                log.Debug("_contributionTypeService.GetContributionType - " + ContributionTypeViewModel.FormatContributionTypeViewModel(contributionType));

                log.Debug("result: 'success'");

                //return Json(contributionType, JsonRequestBehavior.AllowGet);
                //return Content(JsonConvert.SerializeObject(contributionType), "application/json");
                //return contributionType;
                //return JsonConvert.SerializeObject(contributionType);
                return(Ok(contributionType));
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
コード例 #2
0
        private ContributionTypeDTO Create(ContributionTypeViewModel viewModel)
        {
            try
            {
                log.Debug(ContributionTypeViewModel.FormatContributionTypeViewModel(viewModel));

                ContributionTypeDTO contributionType = new ContributionTypeDTO();

                // copy values
                viewModel.UpdateDTO(contributionType, null); //RequestContext.Principal.Identity.GetUserId());

                // audit
                contributionType.CreateBy = null; //RequestContext.Principal.Identity.GetUserId();
                contributionType.CreateOn = DateTime.UtcNow;

                // add
                log.Debug("_contributionTypeService.AddContributionType - " + ContributionTypeDTO.FormatContributionTypeDTO(contributionType));

                int id = _contributionTypeService.AddContributionType(contributionType);

                contributionType.ContributionTypeId = id;

                log.Debug("result: 'success', id: " + id);

                return(contributionType);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
コード例 #3
0
        //[ValidateAntiForgeryToken]
        public IHttpActionResult Upsert(ContributionTypeViewModel viewModel)
        {
            log.Debug("Upsert");

            if (viewModel.ContributionTypeId > 0)
            {
                var t = Update(viewModel);
                //return Json(true);
                //return JsonConvert.SerializeObject(t.ContributionTypeId);
                return(Ok(t.ContributionTypeId));
            }
            else
            {
                var t = Create(viewModel);
                //return Json(t.ContributionTypeId);
                //return JsonConvert.SerializeObject(t.ContributionTypeId);
                return(Ok(t.ContributionTypeId));
            }
        }
コード例 #4
0
        private ContributionTypeDTO Update(ContributionTypeViewModel viewModel)
        {
            try
            {
                log.Debug(ContributionTypeViewModel.FormatContributionTypeViewModel(viewModel));

                // get
                log.Debug("_contributionTypeService.GetContributionType - contributionTypeId: " + viewModel.ContributionTypeId + " ");

                var existingContributionType = _contributionTypeService.GetContributionType(viewModel.ContributionTypeId);

                log.Debug("_contributionTypeService.GetContributionType - " + ContributionTypeDTO.FormatContributionTypeDTO(existingContributionType));

                if (existingContributionType != null)
                {
                    // copy values
                    viewModel.UpdateDTO(existingContributionType, null); //RequestContext.Principal.Identity.GetUserId());

                    // update
                    log.Debug("_contributionTypeService.UpdateContributionType - " + ContributionTypeDTO.FormatContributionTypeDTO(existingContributionType));

                    _contributionTypeService.UpdateContributionType(existingContributionType);

                    log.Debug("result: 'success'");
                }
                else
                {
                    log.Error("existingContributionType: null, ContributionTypeId: " + viewModel.ContributionTypeId);
                }

                return(existingContributionType);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
コード例 #5
0
        //[ValidateAntiForgeryToken]
        public IHttpActionResult SaveList(ContributionTypeViewModel[] viewModels, int?id)
        {
            try
            {
                log.Debug("SaveList");

                if (viewModels != null)
                {
                    // save list
                    foreach (ContributionTypeViewModel viewModel in viewModels)
                    {
                        log.Debug(ContributionTypeViewModel.FormatContributionTypeViewModel(viewModel));

                        if (viewModel.ContributionTypeId > 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;
            }
        }