Beispiel #1
0
        /// <summary>
        /// 创建专辑
        /// </summary>
        /// <param name="model"></param>
        /// <returns>专辑id</returns>
        public static string Create(ManageAlbumViewModel model)
        {
            using (MR_DataClassesDataContext _db = new MR_DataClassesDataContext())
            {
                tbl_Album album = new tbl_Album()
                {
                    album_Title   = model.Title,
                    album_Summary = model.Summary,
                    album_User    = model.UserId,
                    album_Cover   = model.Cover
                };

                string guid;
                do
                {
                    guid = Guid.NewGuid().ToString("N").ToUpper();
                } while (_db.tbl_Album.Where(p => p.album_Id == guid).Count() != 0);
                album.album_Id    = guid;
                album.album_Item  = "[]";
                album.album_Visit = 0;

                _db.tbl_Album.InsertOnSubmit(album);
                _db.SubmitChanges();
                _db.SetAlbumTime(guid);

                return(album.album_Id);
            }
        }
        public ActionResult Edit(string id)
        {
            if (!AlbumManager.Exist(id))
            {
                return(RedirectToAction("NotFound", "Error"));
            }
            ManageAlbumViewModel album = new ManageAlbumViewModel(_db.tbl_Album.SingleOrDefault(s => s.album_Id == id));

            return(View(album));
        }
        public ActionResult Delete(string id, string returnurl)
        {
            if (!AlbumManager.Exist(id))
            {
                return(RedirectToAction("NotFound", "Error"));
            }
            ViewBag.ReturnUrl = returnurl;
            ManageAlbumViewModel album = new ManageAlbumViewModel(_db.tbl_Album.SingleOrDefault(s => s.album_Id == id));

            return(View(album));
        }
Beispiel #4
0
        /// <summary>
        /// 修改专辑
        /// </summary>
        /// <param name="model"></param>
        public static void Edit(ManageAlbumViewModel model)
        {
            using (MR_DataClassesDataContext _db = new MR_DataClassesDataContext())
            {
                var album = _db.tbl_Album.SingleOrDefault(a => a.album_Id == model.Id);

                album.album_Title   = model.Title;
                album.album_Summary = model.Summary;
                if (!string.IsNullOrEmpty(model.Cover) && !string.IsNullOrWhiteSpace(model.Cover))
                {
                    album.album_Cover = model.Cover;
                }

                _db.SubmitChanges();
                _db.AlterAlbumAlterTime(album.album_Id);
            }
        }
 public ActionResult Create(ManageAlbumViewModel model, System.Web.HttpPostedFileBase file)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     if (file != null && file.ContentLength > 0)
     {
         var fileName = System.IO.Path.Combine(Request.MapPath("~/Content/Album/"), System.IO.Path.GetFileName(file.FileName));
         file.SaveAs(fileName);
         model.Cover = System.IO.Path.GetFileName(file.FileName);
     }
     else
     {
         model.Cover = "Album_1.jpg";
     }
     model.UserId = AccountManager.GetId(CookieHepler.GetCookie("user"));
     model.Id     = AlbumManager.Create(model);
     return(RedirectToAction("Detail", new { id = model.Id }));
 }
 public ActionResult Create(ManageAlbumViewModel model, System.Web.HttpPostedFileBase file)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     if (file != null && file.ContentLength > 0)
     {
         var fileName = System.IO.Path.Combine(Request.MapPath("~/Content/Album/"), System.IO.Path.GetFileName(file.FileName));
         file.SaveAs(fileName);
         model.Cover = System.IO.Path.GetFileName(file.FileName);
     }
     else
     {
         model.Cover = "Album_1.jpg";
     }
     model.UserId = AccountManager.GetId(User.Identity.Name);
     AlbumManager.Create(model);
     return(View(new ManageAlbumViewModel()));
 }
        public ActionResult Edit(ManageAlbumViewModel model, System.Web.HttpPostedFileBase file)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (file != null && file.ContentLength > 0)
            {
                var fileName = System.IO.Path.Combine(Request.MapPath("~/Content/Album/"), System.IO.Path.GetFileName(file.FileName));
                file.SaveAs(fileName);
                model.Cover = System.IO.Path.GetFileName(file.FileName);

                string oldCover = _db.tbl_Album.SingleOrDefault(a => a.album_Id == model.Id).album_Cover;
                if (model.Cover != oldCover && oldCover != "Album_1.jpg")
                {
                    ImageManager.Delete(Server.MapPath("~/Content/Album/" + oldCover));
                }
            }
            AlbumManager.Edit(model);
            ModelState.AddModelError("", "修改成功");
            return(RedirectToAction("Edit", new { id = model.Id }));
        }