Beispiel #1
0
 public static void AddModelErrorRange(this System.Web.Http.ModelBinding.ModelStateDictionary @this, IEnumerable <string> exceptions)
 {
     foreach (var exception in exceptions)
     {
         @this.AddModelError("", exception);
     }
 }
Beispiel #2
0
        public IHttpActionResult Post(
            FolderViewModel folder)
        {
            IHttpActionResult ret = null;

            if (ModelState.IsValid)
            {
                folder.Components = new List <BasicComponentViewModel>();
                if (folder.TargetComponentId > 0)
                {
                    folder.Components.Add(new BasicComponentViewModel()
                    {
                        Id            = folder.TargetComponentId,
                        ComponentType = BgsComponentsEnum.Task
                    });
                }

                var savedFolder = _folderService.AddFolder(folder);
                ret = Created <FolderViewModel>(
                    Request.RequestUri +
                    savedFolder.Id.ToString(),
                    folder);
            }
            else
            {
                System.Web.Http.ModelBinding.ModelStateDictionary errors =
                    BgsHelper.ConvertToModelState(ModelState);

                ret = BadRequest(errors);
            }

            return(ret);
        }
Beispiel #3
0
        public IHttpActionResult Put(int id,
                                     QuestionViewModel question)
        {
            IHttpActionResult ret = null;

            if (ModelState.IsValid)
            {
                if (!String.IsNullOrEmpty(question.SourceTypeString))
                {
                    question.SourceType = (SourceType)Enum.Parse(typeof(SourceType), question.SourceTypeString);
                }
                if (!String.IsNullOrEmpty(question.ControlTypeString))
                {
                    question.ControlType = (ControlType)Enum.Parse(typeof(ControlType), question.ControlTypeString);
                }
                if (question.Validations != null)
                {
                    question.SelectedValidations.AddRange(question.Validations.Where(x => x.IsChecked).Select(s => s.Name));
                }
                question.Id = id;
                _questionService.SaveQuestion(question);
                var ques = _questionService.GetQuestion(id);
                SetEnumData(ques);
                ret = Ok(ques);
            }
            else
            {
                System.Web.Http.ModelBinding.ModelStateDictionary errors =
                    BgsHelper.ConvertToModelState(ModelState);

                ret = BadRequest(errors);
            }

            return(ret);
        }
Beispiel #4
0
 protected override bool ValidatePut(System.Web.Http.ModelBinding.ModelStateDictionary validationDictionary, Client currentClient, ProductBooking entity, object param, params object[] additionalObjects)
 {
     NullCheckValidation.NullValidation(TypeOfName.GetNameFromType <ProductBooking>(), new Dictionary <string, object>()
     {
         { "PriceHT", entity.PriceHT },
         { "PriceTTC", entity.PriceTTC },
     }, validationDictionary);
     return(CommonValidation(validationDictionary, currentClient, entity, param, additionalObjects));
 }
Beispiel #5
0
 protected override bool ValidatePost(System.Web.Http.ModelBinding.ModelStateDictionary validationDictionary, Client currentClient, BookingStepBooking entity, object param, params object[] additionalObjects)
 {
     if (entity.BookingStepConfig == null)
     {
         validationDictionary.AddModelError("CurrentStep", GenericError.CANNOT_BE_NULL_OR_EMPTY);
     }
     if (BookingStepBookingRepository.GetBookingStepBookingById(entity.Id, currentClient.Id) != null)
     {
         validationDictionary.AddModelError("BookingStepBooking", GenericError.ALREADY_EXISTS);
     }
     return(CommonValidation(validationDictionary, currentClient, entity, param, additionalObjects));
 }
Beispiel #6
0
        public static void RemoveFor <TModel>(this Http.ModelStateDictionary modelState,
                                              Expression <Func <TModel, object> > expression)
        {
            string expressionText = ExpressionHelper.GetExpressionText(expression);

            foreach (var ms in modelState.ToArray())
            {
                if (ms.Key.Contains("." + expressionText))
                {
                    modelState.Remove(ms);
                }
            }
        }
Beispiel #7
0
        public static string GetFullErrorMessage(this System.Web.Http.ModelBinding.ModelStateDictionary modelState)
        {
            var messages = new List <string>();

            foreach (var entry in modelState)
            {
                foreach (var error in entry.Value.Errors)
                {
                    messages.Add(error.ErrorMessage);
                }
            }

            return(String.Join(" ", messages));
        }
Beispiel #8
0
 public virtual bool MailStepValidation(System.Web.Http.ModelBinding.ModelStateDictionary validationDictionary, Client currentClient, HomeConfig hc, BookingStepBooking entity, MailBookingModel model, object param, params object[] additionalObjects)
 {
     if (hc == null)
     {
         validationDictionary.AddModelError("HomeConfig", GenericError.CANNOT_BE_NULL_OR_EMPTY);
         return(false);
     }
     if (hc.DefaultMailConfig != null && String.IsNullOrEmpty(model.Password))
     {
         validationDictionary.AddModelError(String.Format(GenericNames.MODEL_STATE_FORMAT, TypeOfName.GetNameFromType <MailBookingModel>(), "Password"), GenericError.CANNOT_BE_NULL_OR_EMPTY);
     }
     try
     {
         if (hc.DefaultMailConfig != null && !String.IsNullOrEmpty(model.Password))
         {
             model.Password = Encoding.UTF8.GetString(Convert.FromBase64String(model.Password));
         }
     }
     catch (Exception e)
     {
         if (e is FormatException || e is ArgumentNullException)
         {
             validationDictionary.AddModelError(String.Format(GenericNames.MODEL_STATE_FORMAT, TypeOfName.GetNameFromType <MailBookingModel>(), "Password"), GenericError.INVALID_GIVEN_PARAMETER);
         }
         else
         {
             throw;
         }
     }
     if (hc.DefaultMailConfig == null && entity.MailSent == MAX_SENT)
     {
         validationDictionary.AddModelError(String.Format(GenericNames.MODEL_STATE_FORMAT, TypeOfName.GetNameFromType <Booking>(), "MailSent"), GenericError.DOES_NOT_MEET_REQUIREMENTS);
     }
     if (entity.CurrentStep == null)
     {
         validationDictionary.AddModelError(String.Format(GenericNames.MODEL_STATE_FORMAT, TypeOfName.GetNameFromType <Booking>(), "CurrentStep"), GenericError.CANNOT_BE_NULL_OR_EMPTY);
     }
     if (entity.CurrentStep != null && entity.CurrentStep.MailTemplate == null)
     {
         validationDictionary.AddModelError(String.Format(GenericNames.MODEL_STATE_FORMAT, TypeOfName.GetNameFromType <Booking>(), "MailTemplate"), GenericError.CANNOT_BE_NULL_OR_EMPTY);
     }
     if (entity.Booking.People == null)
     {
         validationDictionary.AddModelError(String.Format(GenericNames.MODEL_STATE_FORMAT, TypeOfName.GetNameFromType <Booking>(), "People"), GenericError.CANNOT_BE_NULL_OR_EMPTY);
     }
     return(validationDictionary.IsValid);
 }
Beispiel #9
0
        public PrettyHttpError(System.Web.Http.ModelBinding.ModelStateDictionary modelState)
        {
            Message = "Your request is invalid.";
            Errors  = new List <string>();

            foreach (var item in modelState)
            {
                foreach (var childItem in item.Value.Errors)
                {
                    Errors.Add(childItem.ErrorMessage);
                }

                if (Errors.Count == 0)
                {
                    continue;
                }
            }
        }
Beispiel #10
0
        public static void AddErrors <TModel>(Expression <Func <TModel, TModel> > modelExpression,
                                              modelBinding.ModelStateDictionary modelState, Response <TModel> response)
        {
            string modelPrefix = ((MemberExpression)modelExpression.Body).Member.Name + ".";

            if (response.ServerValidationErrors == null)
            {
                response.ServerValidationErrors = new List <ServerValidationError>();
            }
            response.ServerValidationErrors.AddRange(
                modelState.Select(delegate(KeyValuePair <string, modelBinding.ModelState> error)
            {
                return(new ServerValidationError
                {
                    Key = error.Key.StartsWith(modelPrefix) ? error.Key.Substring(modelPrefix.Length) : error.Key,
                    Value = string.Join(", ", error.Value.Errors.Select(x => x.ErrorMessage))
                });
            }));
        }
Beispiel #11
0
        public IHttpActionResult Put(int id,
                                     FolderViewModel folder)
        {
            IHttpActionResult ret = null;

            if (ModelState.IsValid)
            {
                folder.Id = id;
                _folderService.UpdateFolder(folder);
                ret = Ok(folder);
            }
            else
            {
                System.Web.Http.ModelBinding.ModelStateDictionary errors =
                    BgsHelper.ConvertToModelState(ModelState);

                ret = BadRequest(errors);
            }

            return(ret);
        }
        public IHttpActionResult Put(int id,
                                     ResponsibilityViewModel responsibility)
        {
            IHttpActionResult ret = null;

            if (ModelState.IsValid)
            {
                responsibility.Id = id;
                _responsibilityService.UpdateResponsibility(responsibility);
                ret = Ok(responsibility);
            }
            else
            {
                System.Web.Http.ModelBinding.ModelStateDictionary errors =
                    BgsHelper.ConvertToModelState(ModelState);

                ret = BadRequest(errors);
            }

            return(ret);
        }
Beispiel #13
0
        public IHttpActionResult Put(int id,
                                     BasicTaskViewModel task)
        {
            IHttpActionResult ret = null;

            if (ModelState.IsValid)
            {
                task.Id = id;
                _taskService.UpdateTask(task);
                ret = Ok(task);
            }
            else
            {
                System.Web.Http.ModelBinding.ModelStateDictionary errors =
                    BgsHelper.ConvertToModelState(ModelState);

                ret = BadRequest(errors);
            }

            return(ret);
        }
        public IHttpActionResult Put(int id,
                                     StepViewModel step)
        {
            IHttpActionResult ret = null;

            if (ModelState.IsValid)
            {
                step.Id = id;
                _stepService.UpdateStep(step);
                ret = Ok(step);
            }
            else
            {
                System.Web.Http.ModelBinding.ModelStateDictionary errors =
                    BgsHelper.ConvertToModelState(ModelState);

                ret = BadRequest(errors);
            }

            return(ret);
        }
Beispiel #15
0
        public IHttpActionResult Post(
            BasicTaskViewModel task)
        {
            IHttpActionResult ret = null;

            if (ModelState.IsValid)
            {
                var savedTask = _taskService.AddTask(task);
                ret = Created <BasicTaskViewModel>(
                    Request.RequestUri +
                    savedTask.Id.ToString(),
                    task);
            }
            else
            {
                System.Web.Http.ModelBinding.ModelStateDictionary errors =
                    BgsHelper.ConvertToModelState(ModelState);

                ret = BadRequest(errors);
            }

            return(ret);
        }
        public IHttpActionResult Post(
            RoleViewModel role)
        {
            IHttpActionResult ret = null;

            if (ModelState.IsValid)
            {
                var savedRole = _roleService.AddRole1(role);
                ret = Created <RoleViewModel>(
                    Request.RequestUri +
                    savedRole.Id.ToString(),
                    role);
            }
            else
            {
                System.Web.Http.ModelBinding.ModelStateDictionary errors =
                    BgsHelper.ConvertToModelState(ModelState);

                ret = BadRequest(errors);
            }

            return(ret);
        }
        public IHttpActionResult Post(
            StepViewModel step)
        {
            IHttpActionResult ret = null;

            if (ModelState.IsValid)
            {
                var savedStep = _stepService.AddStep(step);
                ret = Created <StepViewModel>(
                    Request.RequestUri +
                    savedStep.Id.ToString(),
                    step);
            }
            else
            {
                System.Web.Http.ModelBinding.ModelStateDictionary errors =
                    BgsHelper.ConvertToModelState(ModelState);

                ret = BadRequest(errors);
            }

            return(ret);
        }