コード例 #1
0
        public ActionResult TryEditNewspaper(AddNewspaperModel model)
        {
            if (model != null)
            {
                Newspaper newspaper = DataContext.Newspapers.FirstOrDefault(np => np.Id == model.Id);
                newspaper.Title       = model.Title;
                newspaper.Periodicity = model.Periodicity;
                newspaper.Date        = model.Date;
                newspaper.Price       = model.Price;
                newspaper.Amount      = model.Amount;
                newspaper.PhotoId     = model?.PhotoId;
                DataContext.SubmitChanges();

                return(RedirectToAction("Index", "Newspapers"));
            }
            return(RedirectToAction("EditNewspaper", "Newspapers"));
        }
コード例 #2
0
        public ActionResult TryAddNewspaper(AddNewspaperModel model)
        {
            if (model == null)
            {
                return(RedirectToAction("AddNewspaper", "Newspapers"));
            }
            if (CurrentUser == null || !CurrentUser.IsAdmin)
            {
                return(RedirectToAction("Index", "Newspapers"));
            }

            DataContext.Newspapers.InsertOnSubmit(new Newspaper()
            {
                Title       = model.Title,
                Periodicity = model.Periodicity,
                Amount      = model.Amount,
                Date        = model.Date,
                Price       = model.Price,
                PhotoId     = model?.PhotoId
            });
            DataContext.SubmitChanges();

            return(RedirectToAction("Index", "Newspapers"));
        }