public ActionResult Create(ContentViewModel model, string saveclose) { ContentViewModel remodel = new ContentViewModel(); var actionStatus = new ActionResultHelper(); actionStatus.ActionStatus = ResultSubmit.failed; string errorString = ""; string message = ""; bool IsValid = true; if (ModelState.IsValid) { model.CreatedBy = CurrentUser.UserID; model.ModifiedBy = CurrentUser.UserID; //var culture = Session[CommonConstants.CurrentCulture]; model.Language = currentCulture.ToString(); model.CatalogueId = SiteConfiguration.CatalogueId; remodel = dao.Create(model, out message); if (remodel != null && String.IsNullOrEmpty(message)) { actionStatus.ActionStatus = ResultSubmit.success; actionStatus.Message = String.Format(SiteResource.HTML_ALERT_SUCCESS, Resources.MSG_THE_CONTENT_HAS_CREATED_SUCCESSFULLY); Session[SessionName.ActionStatusLog] = actionStatus; if (!String.IsNullOrEmpty(saveclose)) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Edit", new { id = remodel.ID })); } } else { IsValid = false; errorString = Resources.MSG_THE_CONTENT_HAS_CREATED_UNSUCCESSFULLY; goto actionError; } } else { IsValid = false; goto actionError; } actionError: if (!IsValid) { actionStatus.ErrorReason = String.Format(SiteResource.HTML_ALERT_ERROR, Resources.MSG_ERROR_ENTER_DATA_FOR_FORM + errorString); Session[SessionName.ActionStatusLog] = actionStatus; } ViewBag.Title = Resources.LABEL_CREATE_NEW_CONTENT; return(View("Edit", model)); }
public ActionResult Create(Content model) { if (ModelState.IsValid) { var db = new ContentDao(); long content = db.Create(model); if (content > 0) { SetAlert("Bạn đã thêm mới content thành công", "alert-success"); return(RedirectToAction("Index", "Content")); } else { ModelState.AddModelError("", "Thêm mới thất bại"); } } SetViewBag(); return(View()); }
[ValidateAntiForgeryToken] //bao mat public ActionResult Create(ContentModel model) { // TODO: Add insert logic here if (ModelState.IsValid) { var session = (UserLogin)Session[CommonConstants.USER_SESSION]; model.CreatedBy = session.UserName.ToString(); var dao = new ContentDao(); var content = new Content(); content.CategoryID = model.CategoryID; content.CreatedDate = model.CreatedDate; content.Description = model.Description; content.Detail = AntiXssEncoder.XmlAttributeEncode(content.Detail); content.Image = model.Image; content.Language = model.Language; content.MetaDescriptions = model.MetaDescriptions; content.MetaKeywords = model.MetaKeywords; content.MetaDescriptions = model.MetaDescriptions; content.Name = model.Name; content.Status = model.Status; content.Tags = model.Tags; content.TopHot = model.TopHot; long id = dao.Create(content); if (id > 0) { SetAlert("Thêm tin tức thành công", "success"); return(RedirectToAction("Index", "Content")); } else { SetAlert("Thêm tin tức không thành công", "error"); ModelState.AddModelError("", "Thêm Noi dung không thành công."); } } SetViewBag(); SetAlert("Thêm tin tức không thành công", "error"); return(View("Create")); }
public ActionResult Create(Content model) { if (ModelState.IsValid) { var session = (UserLogin)Session[CommonConstants.USER_SESSION]; model.CreatedBy = session.UserName; var dao = new ContentDao(); long id = dao.Create(model); if (id > 0) { SetAlert("Thêm thông tin thành công", "success"); return(RedirectToAction("Index", "Content")); } else { SetAlert("Thêm user không thành công", "error"); ModelState.AddModelError("", "Thêm thông tin không thành công"); } } SetViewBag(); return(View()); }