public ActionResult CreateCeleb(ManageCelebViewModel celeb, System.Web.HttpPostedFileBase file) { if (!ModelState.IsValid) { return(View(celeb)); } if (file != null && file.ContentLength > 0) { var fileName = System.IO.Path.Combine(Request.MapPath("~/Content/Celeb/"), System.IO.Path.GetFileName(file.FileName)); file.SaveAs(fileName); celeb.Avatar = System.IO.Path.GetFileName(file.FileName); } if ((bool)_db.tbl_UserAccount.SingleOrDefault(u => u.user_Account == User.Identity.Name).user_IsAdmin) { celeb.Status = 2; } else { celeb.Status = 0; } celeb.Create = AccountManager.GetId(User.Identity.Name); string newId = CelebManager.CreateCeleb(celeb); return(RedirectToAction("Edit", new { id = newId })); }
public ActionResult Delete(string id) { if (!CelebManager.Exist(id)) { return(RedirectToAction("NotFound", "Error")); } tbl_Celebrity tblceleb = _db.tbl_Celebrity.SingleOrDefault(s => s.celeb_Id == id); ManageCelebViewModel celeb = new ManageCelebViewModel(tblceleb); return(View(celeb)); }
public ActionResult RefreshConfirm(string id) { if (!CelebManager.Exist(id)) { return(RedirectToAction("NotFound", "Error")); } ManageCelebViewModel newceleb = TempData["NewCeleb"] as ManageCelebViewModel; if (!ModelState.IsValid) { return(RedirectToAction("Edit", new { id = newceleb.Id })); } CelebManager.Edit(newceleb); return(RedirectToAction("Edit", new { id = newceleb.Id })); }
public ActionResult CreateCeleb(ManageCelebViewModel celeb, System.Web.HttpPostedFileBase file) { if (!ModelState.IsValid) { return(View(celeb)); } if (file != null && file.ContentLength > 0) { var fileName = System.IO.Path.Combine(Request.MapPath("~/Content/Celeb/"), System.IO.Path.GetFileName(file.FileName)); file.SaveAs(fileName); celeb.Avatar = System.IO.Path.GetFileName(file.FileName); } string newId = CelebManager.CreateCeleb(celeb); return(RedirectToAction("Edit", new { id = newId })); }
public ActionResult Delete(string id, string returnurl) { if (!CelebManager.Exist(id)) { return(RedirectToAction("NotFound", "Error")); } //if (id == null) //{ // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); // return HttpNotFound(); //} tbl_Celebrity tblceleb = _db.tbl_Celebrity.SingleOrDefault(s => s.celeb_Id == id); ManageCelebViewModel celeb = new ManageCelebViewModel(tblceleb); ViewBag.ReturnUrl = returnurl; return(View(celeb)); }
/// <summary> /// 创建影人 /// </summary> /// <param name="celeb"></param> /// <returns></returns> public static string CreateCeleb(ManageCelebViewModel celeb) { //using (MR_DataClassesDataContext _db = new MR_DataClassesDataContext()) using (MRDataEntities _db = new MRDataEntities()) { string guid; do { guid = Guid.NewGuid().ToString("N").ToUpper(); } while (_db.tbl_Celebrity.Where(p => p.celeb_Id == guid).Count() != 0); celeb.Gender = Translator.GenderToId(celeb.Gender); var createCeleb = new tbl_Celebrity() { celeb_Id = guid, celeb_Name = celeb.Name, celeb_NameEn = celeb.NameEn, celeb_Aka = celeb.Aka, celeb_AkaEn = celeb.AkaEn, celeb_Gender = celeb.Gender, celeb_Birthday = celeb.Birthday, celeb_Deathday = celeb.Deathday, celeb_BornPlace = celeb.BornPlace, celeb_Pro = celeb.Pro, celeb_Family = celeb.Family, celeb_Summary = celeb.Summary, celeb_DoubanID = celeb.DoubanID, celeb_IMDbID = celeb.IMDbID, celeb_Create = celeb.Create, celeb_Status = celeb.Status, celeb_Avatar = celeb.Avatar == null ? "Celeb_1.jpg" : celeb.Avatar }; //_db.tbl_Celebrity.InsertOnSubmit(createCeleb); //_db.SubmitChanges(); //_db.SetCelebTime(guid); _db.tbl_Celebrity.Add(createCeleb); _db.SaveChanges(); return(createCeleb.celeb_Id); } }
public ActionResult Edit(ManageCelebViewModel 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/Celeb/"), System.IO.Path.GetFileName(file.FileName)); file.SaveAs(fileName); model.Avatar = System.IO.Path.GetFileName(file.FileName); string oldAvatar = _db.tbl_Celebrity.SingleOrDefault(c => c.celeb_Id == model.Id).celeb_Avatar; if (model.Avatar != oldAvatar && oldAvatar != "Celeb_1.jpg") { ImageManager.Delete(Server.MapPath("~/Content/Celeb/" + oldAvatar)); } } CelebManager.Edit(model); return(RedirectToAction("Edit", new { id = model.Id })); }
/// <summary> /// 修改影人 /// </summary> /// <param name="celeb"></param> public static void Edit(ManageCelebViewModel celeb) { using (MR_DataClassesDataContext _db = new MR_DataClassesDataContext()) { bool hasChange = false; var oldCeleb = _db.tbl_Celebrity.SingleOrDefault(p => p.celeb_Id == celeb.Id); #region 是否修改过 if (oldCeleb.celeb_Name != celeb.Name) { oldCeleb.celeb_Name = celeb.Name; hasChange = true; } if (oldCeleb.celeb_NameEn != celeb.NameEn) { oldCeleb.celeb_NameEn = celeb.NameEn; hasChange = true; } if (oldCeleb.celeb_Aka != celeb.Aka) { oldCeleb.celeb_Aka = celeb.Aka; hasChange = true; } if (oldCeleb.celeb_AkaEn != celeb.AkaEn) { oldCeleb.celeb_AkaEn = celeb.AkaEn; hasChange = true; } if (oldCeleb.celeb_Gender != Translator.GenderToId(celeb.Gender)) { oldCeleb.celeb_Gender = Translator.GenderToId(celeb.Gender); hasChange = true; } if (oldCeleb.celeb_Birthday != celeb.Birthday) { oldCeleb.celeb_Birthday = celeb.Birthday; hasChange = true; } if (oldCeleb.celeb_BornPlace != celeb.BornPlace) { oldCeleb.celeb_BornPlace = celeb.BornPlace; hasChange = true; } if (oldCeleb.celeb_Pro != celeb.Pro) { oldCeleb.celeb_Pro = celeb.Pro; hasChange = true; } if (oldCeleb.celeb_Family != celeb.Family) { oldCeleb.celeb_Family = celeb.Family; hasChange = true; } if (oldCeleb.celeb_DoubanID != celeb.DoubanID) { oldCeleb.celeb_DoubanID = celeb.DoubanID; hasChange = true; } if (oldCeleb.celeb_IMDbID != celeb.IMDbID) { oldCeleb.celeb_IMDbID = celeb.IMDbID; hasChange = true; } if (oldCeleb.celeb_Summary != celeb.Summary) { oldCeleb.celeb_Summary = celeb.Summary; hasChange = true; } if (oldCeleb.celeb_Avatar != celeb.Avatar) { oldCeleb.celeb_Avatar = celeb.Avatar; hasChange = true; } #endregion if (hasChange) { _db.SubmitChanges(); _db.AlterCelebAlterTime(celeb.Id); } } }