Пример #1
0
        public ActionResult Create(
            [Bind(
                 Include =
                     "Id,Name,Nationality,ClubName,Position,WeakFootRating,SkillMovesRating,MinWorth,MaxWorth,Foot")] Player player, Skill skill, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                var playerCtx = new PlayerRepository();
                if (file != null && file.ContentLength > 0)
                {
                    var imageResizer        = new ImageProcessor.ImageResizer();
                    var playerImagePath     = imageResizer.WriteImage(file.InputStream, "Player");
                    var clubNationImagePath = playerCtx.GetClubAndNationImage(player.Nationality, player.ClubName);
                    var ratingObj           = FifaRatingAlgorithm.CalculateRating(skill, player.Position);
                    var playerObj           = new Player
                    {
                        Name             = player.Name,
                        Position         = player.Position,
                        ClubName         = player.ClubName,
                        Nationality      = player.Nationality,
                        Foot             = player.Foot,
                        MaxWorth         = player.MaxWorth,
                        MinWorth         = player.MinWorth,
                        SkillMovesRating = player.SkillMovesRating,
                        WeakFootRating   = player.WeakFootRating,
                        Image            = new Image
                        {
                            PlayerPath      = playerImagePath,
                            ClubPath        = clubNationImagePath.ClubPath,
                            NationalityPath = clubNationImagePath.NationalityPath
                        },
                        Rating = new Rating
                        {
                            Overall    = ratingObj.Overall,
                            Pace       = ratingObj.Pace,
                            Shooting   = ratingObj.Shooting,
                            Dribbling  = ratingObj.Dribbling,
                            Passing    = ratingObj.Passing,
                            Defense    = ratingObj.Defense,
                            Physical   = ratingObj.Physical,
                            TotalStats = ratingObj.TotalStats
                        },
                        Skill = skill
                    };
                    playerCtx.AddPlayer(playerObj);
                }
                return(RedirectToAction("Index"));
            }


            ViewBag.Id = new SelectList(db.Images, "Id", "PlayerPath", player.Id);
            ViewBag.Id = new SelectList(db.Ratings, "Id", "Id", player.Id);
            return(View(player));
        }
Пример #2
0
 public ActionResult Clubs(HttpPostedFileBase file, string ClubName)
 {
     if (file != null && file.ContentLength > 0)
     {
         var imageResizer = new ImageProcessor.ImageResizer();
         var path         = imageResizer.WriteImage(file.InputStream, "Club");
         var db           = new FifaRepository();
         db.SaveClubInfo(new Models.FifaClub {
             ClubName = ClubName, ClubImagePath = path
         });
     }
     return(View());
 }
Пример #3
0
 public ActionResult Nations(HttpPostedFileBase file, string NationName)
 {
     if (file != null && file.ContentLength > 0)
     {
         var imageResizer = new ImageProcessor.ImageResizer();
         var path         = imageResizer.WriteImage(file.InputStream, "Nation");
         var db           = new FifaRepository();
         db.SaveNationInfo(new FifaNation {
             NationName = NationName, NationImagePath = path
         });
     }
     return(View());
 }