Ejemplo n.º 1
0
        private DistrictDTO Create(DistrictViewModel viewModel)
        {
            try
            {
                log.Debug(DistrictViewModel.FormatDistrictViewModel(viewModel));

                DistrictDTO district = new DistrictDTO();

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

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

                // add
                log.Debug("_districtService.AddDistrict - " + DistrictDTO.FormatDistrictDTO(district));

                int id = _districtService.AddDistrict(district);

                district.DistrictId = id;

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

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

                throw;
            }
        }
Ejemplo n.º 2
0
        private DistrictDTO Update(DistrictViewModel viewModel)
        {
            try
            {
                log.Debug(DistrictViewModel.FormatDistrictViewModel(viewModel));

                // get
                log.Debug("_districtService.GetDistrict - districtId: " + viewModel.DistrictId + " ");

                var existingDistrict = _districtService.GetDistrict(viewModel.DistrictId);

                log.Debug("_districtService.GetDistrict - " + DistrictDTO.FormatDistrictDTO(existingDistrict));

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

                    // update
                    log.Debug("_districtService.UpdateDistrict - " + DistrictDTO.FormatDistrictDTO(existingDistrict));

                    _districtService.UpdateDistrict(existingDistrict);

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

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

                throw;
            }
        }