Example #1
0
        public bool checkValid(CreateFieldScheduleViewModel schedule)
        {
            var      _fieldScheduleService = this.Service <IFieldScheduleService>();
            string   tit   = Utils.GetEnumDescription((FieldScheduleStatus)schedule.Type);
            DateTime start = schedule.StartDate;
            DateTime end   = schedule.EndDate;

            while (start <= end)
            {
                int dayOfWeek      = ((int)start.DayOfWeek) + 1;
                int bitAtPosititon = (schedule.AvailableDay >> dayOfWeek) & 1;
                if (bitAtPosititon == 1)
                {
                    var result = _fieldScheduleService.checkTimeValidInFieldSchedule(schedule.Id, schedule.FieldId, schedule.StartTime, schedule.EndTime, start, start);
                    if (!result)
                    {
                        return(false);
                    }
                }
                start = start.AddDays(1);
            }
            return(true);
        }
Example #2
0
        public ActionResult Update(CreateFieldScheduleViewModel schedule)
        {
            var result = new AjaxOperationResult();

            try
            {
                schedule.StartDate = DateTime.ParseExact(schedule.StartDateStr, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                schedule.EndDate   = DateTime.ParseExact(schedule.EndDateStr, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                schedule.StartTime = TimeSpan.Parse(schedule.StartTimeStr);
                schedule.EndTime   = TimeSpan.Parse(schedule.EndTimeStr);
                string[] days      = schedule.Days.Split(',');
                int      repeatDay = 0;
                for (int i = 0; i < days.Length; i++)
                {
                    if (days[i].Length > 0)
                    {
                        int mark = 1 << Int16.Parse(days[i]);
                        repeatDay = repeatDay | mark;
                    }
                }
                schedule.AvailableDay = repeatDay;
                var userService = this.Service <IAspNetUserService>();
                if (schedule.UserName != null && schedule.UserName.Length > 0)
                {
                    var user = userService.GetActive(u => u.Email.ToLower().Equals(schedule.UserName.ToLower())).FirstOrDefault();
                    if (user != null)
                    {
                        schedule.UserId = user.Id;
                    }
                    else
                    {
                        result.Succeed = false;
                        result.AddError("Update", "Email không tồn tại trong hệ thống. Vui lòng thử lại");
                        return(Json(result));
                    }
                }
                schedule.Active = true;
                var scheduleService = this.Service <IFieldScheduleService>();
                var entity          = scheduleService.Get(schedule.Id);

                if (checkValid(schedule))
                {
                    schedule.CopyToEntity(entity);
                    scheduleService.Update(entity);
                    result.Succeed = true;
                }
                else
                {
                    result.Succeed = false;
                    result.AddError("Update", "Thời gian đặt bị trùng lịch. Vui lòng chọn thời gian khác");
                }
            }
            catch (Exception e)
            {
                result.Succeed = false;
                result.AddError("Update", "Vui lòng nhập đầy đủ thông tin");
            }
            //DateTime startTime = new DateTime(_startDay.Date.Year, _startDay.Date.Month, _startDay.Date.Day, _startTime.Hours, _startTime.Minutes, _startTime.Seconds);
            //DateTime endTime = new DateTime(_endDay.Date.Year, _endDay.Date.Month, _endDay.Date.Day, _endTime.Hours, _endTime.Minutes, _endTime.Seconds);
            //var result = new AjaxOperationResult();



            return(Json(result));
        }