コード例 #1
0
        public ActionResult EditLogo(int?id, LogoBindingModel model)
        {
            if (this.ModelState.IsValid)
            {
                var @event = this.db.Events.Find(id);
                if (@event == null)
                {
                    return(this.HttpNotFound());
                }

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

                if (hasUrl)
                {
                    model.Url = Constants.LogosFolderPath + model.Url;
                    var logo = Mapper.Map <LogoBindingModel, Logo>(model);
                    @event.Logo = logo;

                    this.db.SaveChanges();
                }

                return(this.RedirectToAction("Index"));
            }
            return(this.View(model));
        }
コード例 #2
0
        public ActionResult EditLogoLocal(int?id, LogoBindingModel model)
        {
            if (this.ModelState.IsValid)
            {
                var @event = this.db.Events.Find(id);
                if (@event == null)
                {
                    return(this.HttpNotFound());
                }

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

                var photo = Request.Files["Url"];
                if (photo == null)
                {
                    return(this.View());
                }

                if (hasUrl)
                {
                    var directory = $"{Server.MapPath("~")}{Constants.LogosMapPath}";
                    photo.SaveAs(Path.Combine(directory, photo.FileName));
                    model.Url = Constants.LogosFolderPath + photo.FileName;
                    var logo = Mapper.Map <LogoBindingModel, Logo>(model);
                    @event.Logo = logo;
                    this.db.SaveChanges();
                }

                ViewBag.EventName = @event.Name;

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

            {
                var @event = this.db.Events.Find(id);
                if (@event == null)
                {
                    return(this.HttpNotFound());
                }

                this.ViewBag.EventName = @event.Name;
                this.ViewBag.StartDate = @event.StartDate;
                return(this.View());
            }
        }