Esempio n. 1
0
        public ActionResult EditSermon(SermonView svm)
        {
            if (ModelState.IsValid)
            {
                var sermon    = _uow.Sermons.Get(svm.Id);
                var sermoncat = _uow.SermonCategories.Find(s => s.SermonName == svm.SermonCategoryName).FirstOrDefault();
                if (sermon != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(svm.ImageFile.FileName);
                    string extension = Path.GetExtension(svm.ImageFile.FileName);
                    fileName     = fileName + DateTime.Now.ToString("yymmssffff") + extension;
                    svm.ImageUrl = fileName;
                    fileName     = Path.Combine(Server.MapPath("~/Content/Images/"), fileName);

                    sermon.Bibletext         = svm.SermonText;
                    sermon.Title             = svm.SermonTitle;
                    sermon.SermonDate        = svm.SermonDate;
                    sermon.PreacherName      = svm.PreacherName;
                    sermon.LongDescription   = svm.LongDescription;
                    sermon.ShortDescription  = svm.ShortDescription;
                    sermon.ImageUrl          = svm.ImageUrl;
                    sermon.ImageThumbnailUrl = svm.ImageUrl;

                    sermon.SermonCategory = sermoncat;

                    _uow.Commit();
                    TempData["message"] = $"{sermon.Title} was successfully edited ";
                }
                return(RedirectToAction("SermonList"));
            }
            else
            {
                return(View(svm));
            }
        }
Esempio n. 2
0
        public ActionResult AddSermon(SermonView sv)
        {
            if (ModelState.IsValid)
            {
                var    sermoncat = _uow.SermonCategories.Find(s => s.SermonName == sv.SermonCategoryName).FirstOrDefault();
                string fileName  = Path.GetFileNameWithoutExtension(sv.ImageFile.FileName);
                string extension = Path.GetExtension(sv.ImageFile.FileName);
                fileName    = fileName + DateTime.Now.ToString("yymmssffff") + extension;
                sv.ImageUrl = fileName;
                fileName    = Path.Combine(Server.MapPath("~/Content/Images/"), fileName);
                sv.ImageFile.SaveAs(fileName);



                var addsermon = new Sermon
                {
                    SermonDate        = sv.SermonDate,
                    Title             = sv.SermonTitle,
                    Bibletext         = sv.SermonText,
                    PreacherName      = sv.PreacherName,
                    LongDescription   = sv.LongDescription,
                    ShortDescription  = sv.ShortDescription,
                    SermonCategory    = sermoncat,
                    ImageUrl          = sv.ImageUrl,
                    ImageThumbnailUrl = sv.ImageUrl,
                };
                _uow.Sermons.Add(addsermon);
                _uow.Commit();
                TempData["message"] = string.Format("{0} has been saved.", sv.SermonTitle);
                return(RedirectToAction("SermonList"));
            }
            else
            {
                var sermoncategory = _uow.SermonCategories.GetAll().Select(r => r.SermonName);
                ViewBag.SermonCategory = new SelectList(sermoncategory);
                return(View(sv));
            }
        }
Esempio n. 3
0
        public ActionResult EditSermon(int id)
        {
            var _sermon          = _uow.Sermons.Get(id);
            var sermoncategories = _uow.SermonCategories.GetAll();
            var sermoncat        = _sermon.SermonCategory;

            ViewBag.SermonCategory = new SelectList(sermoncategories, "SermonName", "SermonName", sermoncat.SermonName);

            var svm = new SermonView
            {
                LongDescription    = _sermon.LongDescription,
                ShortDescription   = _sermon.ShortDescription,
                PreacherName       = _sermon.PreacherName,
                SermonCategoryName = _sermon.SermonCategory.SermonName,
                SermonDate         = _sermon.SermonDate,
                SermonText         = _sermon.Bibletext,
                SermonTitle        = _sermon.Title,
                //Id = _sermon.Id,
                ImageUrl = _sermon.ImageUrl,
            };

            return(View(svm));
        }