Exemplo n.º 1
0
        private WeekDayDTO Create(WeekDayViewModel viewModel)
        {
            try
            {
                log.Debug(WeekDayViewModel.FormatWeekDayViewModel(viewModel));

                WeekDayDTO weekDay = new WeekDayDTO();

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

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

                // add
                log.Debug("_weekDayService.AddWeekDay - " + WeekDayDTO.FormatWeekDayDTO(weekDay));

                int id = _weekDayService.AddWeekDay(weekDay);

                weekDay.WeekDayId = id;

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

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

                throw;
            }
        }
Exemplo n.º 2
0
        private WeekDayDTO Update(WeekDayViewModel viewModel)
        {
            try
            {
                log.Debug(WeekDayViewModel.FormatWeekDayViewModel(viewModel));

                // get
                log.Debug("_weekDayService.GetWeekDay - weekDayId: " + viewModel.WeekDayId + " ");

                var existingWeekDay = _weekDayService.GetWeekDay(viewModel.WeekDayId);

                log.Debug("_weekDayService.GetWeekDay - " + WeekDayDTO.FormatWeekDayDTO(existingWeekDay));

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

                    // update
                    log.Debug("_weekDayService.UpdateWeekDay - " + WeekDayDTO.FormatWeekDayDTO(existingWeekDay));

                    _weekDayService.UpdateWeekDay(existingWeekDay);

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

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

                throw;
            }
        }