public ActionResult SetOrderPost(int id, int move) { try { var e = Db.Select <Site_Blog>(x => x.Where(y => y.Id == id)).FirstOrDefault(); if (e != null) { var a = new List <Site_Blog>(); var t = new Site_Blog() { Id = 0 }; if (move == 1) { a = Db.Where <Site_Blog>(x => (x.CategoryId == e.CategoryId && x.Order < e.Order)).OrderBy(x => x.Order).ToList(); if (a.Count != 0) { t = a.Last(); } } else { a = Db.Where <Site_Blog>(x => (x.CategoryId == e.CategoryId && x.Order > e.Order)).OrderBy(x => x.Order).ToList(); if (a.Count != 0) { t = a.First(); } } if (t.Id > 0) { int tmp = t.Order; t.Order = e.Order; e.Order = tmp; Db.Update <Site_Blog>(t); Db.Update <Site_Blog>(e); } } } catch (Exception ex) { return(JsonError(ex.Message)); } return(Json(null, JsonRequestBehavior.AllowGet)); }
public ActionResult Add(int cat_id) { var cat = Db.Where <Site_Blog_Category>(m => m.Id == cat_id).TakeFirst(); if (cat == null) { return(RedirectToAction("Index", "Management")); } Site_Blog model = new Site_Blog(); model.CategoryId = cat.Id; model.CategoryName = cat.Name; model.LanguageCode = cat.LanguageCode; return(View(model)); }
public ActionResult Update(Site_Blog model, string PublishSchedule, string IsActive, IEnumerable <HttpPostedFileBase> FileUp) { model.PublishSchedule = (PublishSchedule != null ? true : false); model.IsActive = (IsActive != null ? true : false); if (string.IsNullOrEmpty(model.Name)) { ViewBag.Error = "Please enter post name"; return(View("Add", model)); } if (model.PublishSchedule && model.PublishOn.CompareTo(model.UnPublishOn) > 0) { ViewBag.Error = "Please check publish schedule date"; return(View("Add", model)); } if (model.Tag != null) { var tag = model.Tag.First(); var tokens = tag.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); model.Tag = tokens.ToList(); } else { model.Tag = new List <string>(); } string random = ""; do { if (string.IsNullOrEmpty(model.SeoName)) { model.SeoName = model.Name + random; model.SeoName = model.SeoName.ToSeoUrl(); } else { model.SeoName = model.SeoName.ToSeoUrl(); } if (Db.Count <Site_Blog>(m => m.SeoName == model.SeoName && m.Id != model.Id) == 0) { break; } random = "_" + random.GenerateRandomText(3); model.SeoName = ""; } while (true); Site_Blog current_item = new Site_Blog(); if (model.Id > 0) { var z = Db.Where <Site_Blog>(m => m.Id == model.Id); if (z.Count == 0) { return(JsonError("Please dont try to hack us")); } else { current_item = z.First(); } } if (model.Id == 0) { model.CreatedOn = DateTime.Now; model.CreatedBy = AuthenticatedUserID; } else { model.CreatedOn = current_item.CreatedOn; model.CreatedBy = current_item.CreatedBy; } if (FileUp != null && FileUp.Count() > 0 && FileUp.First() != null) { model.ThumbnailFile = UploadFile(AuthenticatedUserID, User.Identity.Name, "", FileUp); } else { model.ThumbnailFile = current_item.ThumbnailFile; } if (model.Id == 0) { Db.Insert <Site_Blog>(model); } else { Db.Update <Site_Blog>(model); } return(RedirectToAction("Index", new { cat_id = model.CategoryId })); }