Example #1
0
        private NucleoDTO Create(NucleoViewModel viewModel)
        {
            try
            {
                log.Debug(NucleoViewModel.FormatNucleoViewModel(viewModel));

                NucleoDTO nucleo = new NucleoDTO();

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

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

                // add
                log.Debug("_nucleoService.AddNucleo - " + NucleoDTO.FormatNucleoDTO(nucleo));

                int id = _nucleoService.AddNucleo(nucleo);

                nucleo.NucleoId = id;

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

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

                throw;
            }
        }
Example #2
0
        private NucleoDTO Update(NucleoViewModel viewModel)
        {
            try
            {
                log.Debug(NucleoViewModel.FormatNucleoViewModel(viewModel));

                // get
                log.Debug("_nucleoService.GetNucleo - nucleoId: " + viewModel.NucleoId + " ");

                var existingNucleo = _nucleoService.GetNucleo(viewModel.NucleoId);

                log.Debug("_nucleoService.GetNucleo - " + NucleoDTO.FormatNucleoDTO(existingNucleo));

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

                    // update
                    log.Debug("_nucleoService.UpdateNucleo - " + NucleoDTO.FormatNucleoDTO(existingNucleo));

                    _nucleoService.UpdateNucleo(existingNucleo);

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

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

                throw;
            }
        }