Ejemplo n.º 1
0
        public ActionResult Create(Guid id, PlayerCreateForm createForm)
        {
            var player = this.playerResourceHandler.Create(
                this.adapter.Domain(id.ToString(), createForm));

            return(this.adapter.CreatedResult(player));
        }
Ejemplo n.º 2
0
        public ICollection <string> ValidatePlayer(PlayerCreateForm model)
        {
            var errors = new List <string>();

            if (model.FullName.Length < PlayerFullNameMinLength || model.FullName.Length > PlayerFullNameMaxLength)
            {
                errors.Add($"FullName '{model.FullName}' is not valid. It must be between {PlayerFullNameMinLength} and {PlayerFullNameMaxLength} characters long.");
            }

            if (model.Position.Length < PositionMinlength || model.Position.Length > PositionMaxlength)
            {
                errors.Add($"Position '{model.Position}' is not valid. It must be between {PositionMinlength} and {PositionMaxlength} characters long.");
            }

            if (model.Speed < SpeedMinLength || model.Speed > SpeedMaxLength)
            {
                errors.Add($"Speed '{model.Speed}' is not valid. It must be between {SpeedMinLength} and {SpeedMaxLength} characters long.");
            }

            if (model.Endurance < EnduranceMinLength || model.Endurance > EnduranceMaxLength)
            {
                errors.Add($"Endurance '{model.Endurance}' is not valid. It must be between {EnduranceMinLength} and {EnduranceMaxLength} characters long.");
            }

            if (model.Description.Length > DescriptionMaxLength)
            {
                errors.Add($"Description '{model.Description} is not valid {DescriptionMaxLength} characters long.");
            }

            return(errors);
        }
 public Player Domain(string clubId, PlayerCreateForm createForm)
 {
     return(new Player
     {
         ClubId = clubId,
         Email = createForm.EmailAddress,
         FirstName = createForm.FirstName,
         MiddleNames = createForm.MiddleNames,
         LastName = createForm.LastName,
         ProfileImageUrl = createForm.ProfileImageUrl
     });
 }
        public HttpResponse Add(PlayerCreateForm model)
        {
            var modelErrors = this.validator.ValidatePlayer(model);

            if (modelErrors.Any())
            {
                return(Error(modelErrors));
            }

            var player = new Player()
            {
                FullName    = model.FullName,
                ImageUrl    = model.ImageUrl,
                Position    = model.Position,
                Speed       = model.Speed,
                Endurance   = model.Endurance,
                Description = model.Description
            };

            this.data.Players.Add(player);
            this.data.SaveChanges();

            return(Redirect("/Players/All"));
        }