コード例 #1
0
        public ActionResult EditNews(int id)
        {
            if (Session["Role"] != null && Session["Role"].ToString() == "Administrator")
            {
                AddAchievement item = new AddAchievement();
                item.AchievementItem = db.Achivements.Find(id);

                return View(item);
            }
            else
                return RedirectToAction("Http403", "Error", null);    
        }
コード例 #2
0
        public ActionResult EditNews(AddAchievement a)
        {
            var achievement = db.Achivements.Find(a.AchievementItem.AchievementID);

            if (a.ImageFile != null)
            {
                var image = new WebImage(a.ImageFile.InputStream);
                image.Resize(200, 133);

                achievement.PhotoType = a.ImageFile.ContentType;
                achievement.PhotoFile = image.GetBytes();
            }

            achievement.Title = a.AchievementItem.Title;
            achievement.Description = a.AchievementItem.Description;

            TryUpdateModel<Achievement>(achievement);
            db.Entry<Achievement>(achievement).State = System.Data.EntityState.Modified;
            db.SaveChanges();

            return RedirectToAction("SystemNewsCreation");
        }
コード例 #3
0
        public ActionResult CreateNews(AddAchievement achievement, int ecologicalProblemID)
        {
            ViewBag.problemID = ecologicalProblemID;            
            int currentAdminId;

            if (int.TryParse(Session["SystemUserId"].ToString(), out currentAdminId))
            {
                try
                {
                    achievement.AchievementItem.Administrator = db.Administrators.Find(currentAdminId);
                    achievement.AchievementItem.EcologicalProblem = db.EcologicalProblems.Find(ecologicalProblemID);

                    if (achievement.ImageFile != null)
                    {
                        var image = new WebImage(achievement.ImageFile.InputStream);
                        image.Resize(200, 133);

                        achievement.AchievementItem.PhotoType = achievement.ImageFile.ContentType;
                        achievement.AchievementItem.PhotoFile = image.GetBytes();
                    }

                    db.Achivements.Add(achievement.AchievementItem);
                    db.SaveChanges();

                    return RedirectToAction("SystemNewsCreation");
                }
                catch { }
            }

            return View();
        }