Example #1
0
        public ActionResult Update(ContainerModel model)
        {
            var ipAddress = GetIP(Request);

            if (ModelState.IsValid)
            {
                var user = Converter.UserModelToUser(model);

                // check choices consistency
                var places = FoodChoiceService.GetPlaces();
                ValidationService.RemoveInvalidEntry(user, places);

                var errorMessage = string.Empty;
                if (ValidationService.ControlCheckBoxes(user, out errorMessage))
                {
                    FoodChoiceService.UpdateUser(user, ipAddress);
                    logger.Debug("Modification de l'utilisateur: {0} - IP: {1}", user.Name, ipAddress);
                }
                return(RedirectToAction("Index"));
            }
            else
            {
                // errors are not managed
                logger.Error("Erreur lors de la modification: {0} - IP: {1}", model.FoodChoice.Name, ipAddress);
                return(RedirectToAction("Index"));
            }
        }
Example #2
0
        public void ControlCheckBoxes_IMadeChoices()
        {
            var errorMessage = string.Empty;
            var user         = new User
            {
                AvailableSeats = 2,
                Choices        = new List <Choice>
                {
                    new Choice {
                        Place = new Place {
                            Label = "Carrefour"
                        }
                    },
                    new Choice {
                        Place = new Place {
                            Label = "Quick"
                        }
                    },
                    new Choice {
                        Place = new Place {
                            Label = "Autre"
                        }
                    },
                }
            };

            var service = new ValidationService();
            var result  = service.ControlCheckBoxes(user, out errorMessage);

            Assert.IsTrue(result);
            Assert.IsTrue(string.IsNullOrEmpty(errorMessage));
        }
Example #3
0
        public void ControlCheckBoxes_NoChoiceMade()
        {
            var errorMessage = string.Empty;
            var user         = new User
            {
                Choices = new List <Choice>()
            };

            var service = new ValidationService();
            var result  = service.ControlCheckBoxes(user, out errorMessage);

            Assert.IsFalse(result);
            Assert.AreEqual("Merci de cocher au moins une case !", errorMessage);
        }