//Phương thức này sử dụng cho ajax public int ChangeTopHot(long id) { //Giá trị trả về // 0 là đang có // 1 là TopHot = true // 2 là TopHot = fasle int final = 100; LawCorner selectedObj = db.LawCorners.Find(id); //Nếu TopHot của LawCorner đang được chọn là false thì cần kiểm tra xem hiện đang có LawCorner nào thuộc TopHot không? if (selectedObj.TopHot == false) { var result = db.LawCorners.Where(x => x.TopHot == true && x.ID != id).Count(); if (result == 0) { //Nếu hiện tại chưa có thì chuyển TopHot của nó thành true selectedObj.TopHot = true; db.SaveChanges(); final = 1; } else { final = 0; } } else { selectedObj.TopHot = false; db.SaveChanges(); final = 2; } return(final); }
public ActionResult UpdateLawCorner(LawCorner model) { if (ModelState.IsValid) { var dao = new LawCornerDAO(); UserLogin userlogin = (UserLogin)Session["USER_SESSION"]; model.ModifiedBy = userlogin.UserName; //Kiểm tra xem tên sách này đã có chưa bool exist = dao.LawCornerExistForUpdate(model.Name, model.ID); if (!exist) { string metatitle = CastString.Cast(model.Name); model.MetaTitle = metatitle; bool result = dao.UpdateLawCorner(model); if (result) { SetAltert("Cập nhật thành công", 0); return(RedirectToAction("Index", "LawCorner")); } else { SetAltert("Cập nhật không thành công", 2); } } else { SetAltert("Tiêu đề tin này đã có", 2); } } else { } return(View(model)); }
public ActionResult Create(LawCorner model) { if (ModelState.IsValid) { var dao = new LawCornerDAO(); //Lấy ra user đăng nhập để gán vào CreatedBY UserLogin userlogin = (UserLogin)Session["USER_SESSION"]; model.CreatedBy = userlogin.UserName; bool exits = dao.LawCornerExist(model.Name); if (!exits) { string metatitle = CastString.Cast(model.Name); model.MetaTitle = metatitle; model.CreatedDate = DateTime.Now; bool result = dao.CreateLawCorner(model); if (result) { SetAltert("Tạo tin thành công", 0); return(RedirectToAction("Index", "LawCorner")); } else { SetAltert("Tạo mới không thành công", 2); } } else { SetAltert("Tiêu đề này đã có", 2); } } return(View(model)); }
//Phương thức tạo mới 1 tin luật public bool CreateLawCorner(LawCorner entity) { try { entity.CreatedDate = DateTime.Now; db.LawCorners.Add(entity); db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
//Update sản phẩm phẩm public bool UpdateLawCorner(LawCorner entity) { try { var model = db.LawCorners.Find(entity.ID); model.ModifiedDate = DateTime.Now; model.ModifiedBy = entity.ModifiedBy; model.Name = entity.Name; model.Image = entity.Image; model.Description = entity.Description; model.Detail = entity.Detail; model.Status = entity.Status; model.TopHot = entity.TopHot; model.MetaTitle = entity.MetaTitle; db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }