示例#1
0
 //валидация даты
 private void Date_Validating(object sender, CancelEventArgs e)
 {
     if (dateTimePicker1.Value > today) //дата не может быть больше сегодняшней
     {
         DateError.SetError(dateTimePicker1, "Введенная дата не может быть больше текущей");
     }
     else
     {
         DateError.Clear();
     }
 }
示例#2
0
        public IHttpActionResult ApproveChildcareRequest(int requestId, ChildcareRequestDto childcareRequest)
        {
            if (!ModelState.IsValid)
            {
                var errors    = ModelState.Values.SelectMany(val => val.Errors).Aggregate("", (current, err) => current + err.Exception.Message);
                var dataError = new ApiErrorDto("Save Request Data Invalid", new InvalidOperationException("Invalid Save request Data" + errors));
                throw new HttpResponseException(dataError.HttpResponseMessage);
            }

            return(Authorized(token =>
            {
                try
                {
                    _childcareService.ApproveChildcareRequest(requestId, childcareRequest, token);
                    return Ok();
                }
                catch (EventMissingException e)
                {
                    var errors = new DateError()
                    {
                        Errors = e.MissingDateTimes, Message = e.Message
                    };
                    var json = JsonConvert.SerializeObject(errors, Formatting.Indented);
                    var message = new HttpResponseMessage(HttpStatusCode.RequestedRangeNotSatisfiable);
                    message.Content = new StringContent(json);
                    throw new HttpResponseException(message);
                }
                catch (ChildcareDatesMissingException e)
                {
                    var json = JsonConvert.SerializeObject(e.Message, Formatting.None);
                    var message = new HttpResponseMessage(HttpStatusCode.NotAcceptable);
                    message.Content = new StringContent(json);
                    throw new HttpResponseException(message);
                }
                catch (DuplicateChildcareEventsException e)
                {
                    var error = new DateError()
                    {
                        Error = e.RequestedDate, Message = e.Message
                    };
                    var json = JsonConvert.SerializeObject(error, Formatting.Indented);
                    var message = new HttpResponseMessage(HttpStatusCode.MultipleChoices);
                    message.Content = new StringContent(json);
                    throw new HttpResponseException(message);
                }
                catch (Exception e)
                {
                    var apiError = new ApiErrorDto("Approve Childcare Request Failed", e);
                    throw new HttpResponseException(apiError.HttpResponseMessage);
                }
            }));
        }
示例#3
0
 private ActionResult return_validate_false_view(DateError error)
 {
     switch (error)
     {
         case DateError.FutureDate:
             return View("future_posts");
         case DateError.MonthNotExists:
         case DateError.DayNotExists:
             return View("date_not_exists");
         case DateError.BeforeBloging:
             return View("past_posts");
         default:
             return HttpNotFound();
     }
 }