コード例 #1
0
        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;
            }
        }
コード例 #2
0
        public EnergySourceDTO GetEnergySource(int energySourceId)
        {
            try
            {
                //Requires.NotNegative("energySourceId", energySourceId);

                log.Debug("energySourceId: " + energySourceId + " ");

                // get
                R_EnergySource t = Repository.GetEnergySource(energySourceId);

                EnergySourceDTO dto = new EnergySourceDTO(t);

                log.Debug(EnergySourceDTO.FormatEnergySourceDTO(dto));

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

                throw;
            }
        }
コード例 #3
0
        public int AddEnergySource(EnergySourceDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(EnergySourceDTO.FormatEnergySourceDTO(dto));

                R_EnergySource t = EnergySourceDTO.ConvertDTOtoEntity(dto);

                // add
                id = Repository.AddEnergySource(t);
                dto.EnergySourceId = id;

                log.Debug("result: 'success', id: " + id);
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }

            return(id);
        }
コード例 #4
0
        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;
            }
        }
コード例 #5
0
        public void DeleteEnergySource(EnergySourceDTO dto)
        {
            try
            {
                log.Debug(EnergySourceDTO.FormatEnergySourceDTO(dto));

                R_EnergySource t = EnergySourceDTO.ConvertDTOtoEntity(dto);

                // delete
                Repository.DeleteEnergySource(t);
                dto.IsDeleted = t.IsDeleted;

                log.Debug("result: 'success'");
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
コード例 #6
0
        public void UpdateEnergySource(EnergySourceDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "EnergySourceId");

                log.Debug(EnergySourceDTO.FormatEnergySourceDTO(dto));

                R_EnergySource t = EnergySourceDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateEnergySource(t);

                log.Debug("result: 'success'");
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }