Esempio n. 1
0
        public DtoActionResult Update(EntitySchedule schedule)
        {
            var u = GetSchedule(schedule.Id);

            if (u == null)
            {
                return new DtoActionResult {
                           ErrorMessage = "Schedule Not Found", Id = 0
                }
            }
            ;

            var actionResult = new DtoActionResult();

            var validationResult = Validate(schedule, false);

            if (validationResult.Success)
            {
                _uow.ScheduleRepository.Update(schedule, u.Id);

                _uow.Save();
                actionResult.Success = true;
                actionResult.Id      = schedule.Id;
            }
            else
            {
                return(new DtoActionResult()
                {
                    ErrorMessage = validationResult.ErrorMessage
                });
            }
            return(actionResult);
        }
Esempio n. 2
0
        protected void buttonAddSchedule_OnClick(object sender, EventArgs e)
        {
            var schedule = new EntitySchedule();

            schedule.Name        = txtName.Text;
            schedule.Description = txtDescription.Text;
            schedule.Sunday      = chkSunday.Checked;
            schedule.Monday      = chkMonday.Checked;
            schedule.Tuesday     = chkTuesday.Checked;
            schedule.Wednesday   = chkWednesday.Checked;
            schedule.Thursday    = chkThursday.Checked;
            schedule.Friday      = chkFriday.Checked;
            schedule.Saturday    = chkSaturday.Checked;
            schedule.Hour        = Convert.ToInt16(ddlHour.SelectedValue);
            schedule.Minute      = Convert.ToInt16(ddlMinute.SelectedValue);
            schedule.IsActive    = true;

            var result = Call.ScheduleApi.Post(schedule);

            if (!result.Success)
            {
                EndUserMessage = result.ErrorMessage;
            }
            else
            {
                EndUserMessage = "Successfully Created Schedule";
                Response.Redirect("~/views/global/schedules/edit.aspx?scheduleId=" + result.Id);
            }
        }
Esempio n. 3
0
        public DtoValidationResult Validate(EntitySchedule schedule, bool isNew)
        {
            if (schedule.Hour < 0 || schedule.Hour > 23)
            {
                return new DtoValidationResult()
                       {
                           ErrorMessage = "Hour Was Not Valid", Success = false
                       }
            }
            ;
            if (schedule.Minute != 0 && schedule.Minute != 15 && schedule.Minute != 30 && schedule.Minute != 45)
            {
                return new DtoValidationResult()
                       {
                           ErrorMessage = "Minute Was Not Valid", Success = false
                       }
            }
            ;

            var validationResult = new DtoValidationResult {
                Success = true
            };

            if (string.IsNullOrEmpty(schedule.Name) || !schedule.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-' || c == ' ' || c == '.'))
            {
                validationResult.Success = false;

                validationResult.ErrorMessage = "Schedule Name Is Not Valid";
                return(validationResult);
            }

            if (isNew)
            {
                if (_uow.ScheduleRepository.Exists(h => h.Name == schedule.Name))
                {
                    validationResult.Success      = false;
                    validationResult.ErrorMessage = "A Schedule With This Name Already Exists";
                    return(validationResult);
                }
            }
            else
            {
                var original = _uow.ScheduleRepository.GetById(schedule.Id);
                if (original.Name != schedule.Name)
                {
                    if (_uow.ScheduleRepository.Exists(h => h.Name == schedule.Name))
                    {
                        validationResult.Success      = false;
                        validationResult.ErrorMessage = "A Schedule With This Name Already Exists";
                        return(validationResult);
                    }
                }
            }

            return(validationResult);
        }
Esempio n. 4
0
        public DtoActionResult Put(int id, EntitySchedule schedule)
        {
            schedule.Id = id;
            var result = _scheduleService.Update(schedule);

            if (result == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            return(result);
        }
        public ModelViewPriority Update(ModelViewPriority model)
        {
            var objRepository = new RepositorySchedule();

            var dataOld = new RepositorySchedule().Get(model.ScheduleID);

            EntitySchedule data = new EntitySchedule()
            {
                PK_ScheduleID = dataOld.PK_ScheduleID,
                ScheduleStart = model.ScheduleStart,
                ScheduleEnd   = model.ScheduleEnd,
                Status        = dataOld.Status,
                CreateDate    = dataOld.CreateDate,
                ModifyDate    = DateTime.UtcNow
            };

            data = objRepository.Update(data);

            return(model);
        }
Esempio n. 6
0
        public DtoActionResult Add(EntitySchedule schedule)
        {
            var actionResult = new DtoActionResult();

            var validationResult = Validate(schedule, true);

            if (validationResult.Success)
            {
                _uow.ScheduleRepository.Insert(schedule);
                _uow.Save();
                actionResult.Success = true;
                actionResult.Id      = schedule.Id;
            }
            else
            {
                return(new DtoActionResult()
                {
                    ErrorMessage = validationResult.ErrorMessage
                });
            }

            return(actionResult);
        }
Esempio n. 7
0
 public DtoActionResult Post(EntitySchedule schedule)
 {
     return(_scheduleService.Add(schedule));
 }