Пример #1
0
        public async Task <HttpResponseMessage> Update(HttpRequestMessage request, Holiday holiday)
        {
            return(await CreateHttpResponse(request, () =>
            {
                if (!ModelState.IsValid)
                {
                    return request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                var existHoliday = _holidayService.GetById(holiday.ID);
                if (existHoliday.Date.Date < DateTime.Now.Date && existHoliday.Date.Date != holiday.Date.Date)
                {
                    return request.CreateResponse(HttpStatusCode.BadRequest, MessageSystem.ERROR_HOLIDAY_CREATE_INTHE_PAST);
                }

                if (holiday.Workingday != null && holiday.Workingday.Value.Date < DateTime.Now.Date || existHoliday.Workingday != null && existHoliday.Workingday.Value.Date < DateTime.Now.Date && existHoliday.Workingday.Value.Date != holiday.Workingday.Value.Date)
                {
                    return request.CreateResponse(HttpStatusCode.BadRequest, MessageSystem.ERROR_HOLIDAY_CREATE_INTHE_PAST);
                }
                if (holiday.Workingday != null && holiday.Workingday.Value < DateTime.Now)
                {
                    return request.CreateResponse(HttpStatusCode.BadRequest, MessageSystem.ERROR_HOLIDAY_CREATE_INTHE_PAST);
                }

                var listTimeDay = _timedayService.GetAllTimeDay().ToList();

                if (listTimeDay.FirstOrDefault(x => x.Workingday.Equals(holiday.Date.DayOfWeek.ToString())) == null)
                {
                    return request.CreateResponse(HttpStatusCode.BadRequest, MessageSystem.ERROR_HOLIDAY_CREATE_CONTAIN_HOLIDAY);
                }

                if (listTimeDay.FirstOrDefault(x => holiday.Workingday != null && x.Workingday.Equals(holiday.Workingday.Value.DayOfWeek.ToString())) != null)
                {
                    return request.CreateResponse(HttpStatusCode.BadRequest, MessageSystem.ERROR_HOLIDAY_CREATE_IN_TIMEDAY);
                }

                var listHoliday = _holidayService.Get(null, true).Where(x => x.ID != holiday.ID);
                holiday.Workingday = holiday.Workingday.HasValue ? holiday.Workingday.Value.Date : (DateTime?)null;
                if (listHoliday.FirstOrDefault(x => x.Date == holiday.Date.Date || x.Date == holiday.Workingday ||
                                               x.Workingday.HasValue && x.Workingday == holiday.Date.Date ||
                                               x.Workingday.HasValue && x.Workingday == holiday.Workingday) != null)
                {
                    return request.CreateResponse(HttpStatusCode.BadRequest, MessageSystem.ERROR_HOLIDAY_CREATE_EXISTED);
                }


                _requestService.HandleUpdateHoliday_EntitleDay(holiday, existHoliday);
                holiday.Date = holiday.Date.Date;
                existHoliday.UpdatedDate = DateTime.Now;
                existHoliday.UpdatedBy = User.Identity.Name;
                existHoliday.Date = holiday.Date;
                existHoliday.Workingday = holiday.Workingday;
                existHoliday.Note = !string.IsNullOrEmpty(holiday.Note) ? holiday.Note.Trim() : null;
                _holidayService.Update(existHoliday);
                _holidayService.Save();
                return request.CreateResponse(HttpStatusCode.OK, existHoliday);
            }));
        }
Пример #2
0
        public IActionResult GetById(string id)
        {
            var rs = _iHolidayService.GetById(id);

            return(Ok(rs));
        }