Beispiel #1
0
        public ActionResult EditTeamLogo(int?id, TeamLogoBindingModel model)
        {
            if (this.ModelState.IsValid)
            {
                var team = this.db.Teams.Find(id);
                if (team == null)
                {
                    return(this.HttpNotFound());
                }
                var hasUrl = !string.IsNullOrEmpty(model.Url);
                if (team.TeamLogo != null && hasUrl)
                {
                    this.db.Entry(team.TeamLogo).State = EntityState.Deleted;
                    this.db.SaveChanges();
                }

                if (hasUrl)
                {
                    model.Url = Constants.TeamLogosFolderPath + model.Url;
                    var teamLogo = Mapper.Map <TeamLogoBindingModel, TeamLogo>(model);
                    team.TeamLogo = teamLogo;

                    this.db.SaveChanges();
                }

                ViewBag.TeamName = team.Name;
                return(this.RedirectToAction("Index"));
            }
            return(this.View(model));
        }
Beispiel #2
0
        public ActionResult EditTeamLogoLocal(int?id, TeamLogoBindingModel model)
        {
            if (this.ModelState.IsValid)
            {
                var team = this.db.Teams.Find(id);
                if (team == null)
                {
                    return(this.HttpNotFound());
                }

                var hasUrl = !string.IsNullOrEmpty(model.Url);
                if (team.TeamLogo != null && hasUrl)
                {
                    this.db.Entry(team.TeamLogo).State = EntityState.Deleted;
                    this.db.SaveChanges();
                }

                var image = this.Request.Files["Url"];
                if (image == null)
                {
                    return(this.View());
                }
                var photo = new WebImage(image.InputStream);
                if (photo.Width > 30)
                {
                    photo.Resize(30, 30, false);
                }

                if (hasUrl)
                {
                    var directory = $"{Server.MapPath("~")}{Constants.TeamLogosMapPath}";
                    photo.Save(Path.Combine(directory, photo.FileName));
                    model.Url = Constants.TeamLogosFolderPath + photo.FileName;
                    var teamLogo = Mapper.Map <TeamLogoBindingModel, TeamLogo>(model);
                    team.TeamLogo = teamLogo;
                    this.db.SaveChanges();
                }

                ViewBag.TeamName = team.Name;

                return(this.RedirectToAction("Index"));
            }
            return(this.View());
        }