public ActionResult DeleteWrittings(long writtingId) { // response variable ActionResult response; // checking to see if the writting ids match or admin if (writtingId != (long)Session["UserId"] && (long)Session["Role"] == 1) { response = RedirectToAction("AllUsers", "Account"); } else { // creating variables for writtings and mapping them Do to PO WrittingsDO writtings = WrittingsDataAccess.ViewWrittingsById(writtingId); Writtings deletedWrittings = mapper.MapDoToPo(writtings); long writtingID = deletedWrittings.WrittingId; try { //check to see if id is valid if (writtingId > 0) { // id is valid WrittingsDataAccess.DeleteWritting(writtingId); response = RedirectToAction("AllWrittings", "Writtings"); } else { // not valid response = RedirectToAction("AllWrittings", "Writtings"); } } catch (SqlException Sqlex) { //Log exception for sql logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Sqlex); response = View(writtings); TempData["Message"] = "Connection Error"; } catch (Exception ex) { // log exception for other exceptions logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = View(writtings); TempData["Message"] = "Error Try Again"; } } return(response); }
/// <summary> /// PO to DO /// </summary> /// <param name="from"></param> /// <returns>information out</returns> public WrittingsDO MapPoToDo(Writtings from) { WrittingsDO to = new WrittingsDO(); to.WrittingId = from.WrittingId; to.Username = from.Username; to.Title = from.Title; to.DatePublished = from.DatePublished; to.Content = from.Content; to.UserId = from.UserId; to.WordCount = from.WordCount; return(to); }
public ActionResult UpdateWrittings(long writtingId) { // response variable ActionResult response; // checking if id matches or admin if (writtingId != (long)Session["UserId"] && (long)Session["Role"] == 1) { response = RedirectToAction("AllUsers", "Account"); } else { // mapping what needs to be updated DO to PO WrittingsDO writtings = WrittingsDataAccess.ViewWrittingsById(writtingId); Writtings updateWrittings = mapper.MapDoToPo(writtings); long WrittingId = updateWrittings.WrittingId; try { //check if valid if (writtingId > 0) { // view update writtings response = View(updateWrittings); } else { // redirect if not valid response = RedirectToAction("AllWrittings", "Writtings"); } } catch (SqlException Sqlex) { //Log exception for sql logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Sqlex); response = View(writtings); TempData["Message"] = "Connection Error"; } catch (Exception ex) { // log exception for other exceptions logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = View(writtings); TempData["Message"] = "Error Try Again"; } } return(response); }
public ActionResult CreateWrittings(Writtings form) { // creating the date for the date published form.DatePublished = DateTime.Now.Date; // creating our response variable ActionResult response; try { // checking to see if valid if (ModelState.IsValid) { //pulling the user id from session form.UserId = (long)Session["UserId"]; // using the logic layer for wordcount form.WordCount = logic.CountWords(form.Content); //mapping the writtings WrittingsDO writtings = mapper.MapPoToDo(form); WrittingsDataAccess.CreateWrittings(writtings); response = RedirectToAction("AllWrittings", "Writtings"); } else { // if not valid response = View(form); } } catch (SqlException Sqlex) { //Log exception for sql logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Sqlex); response = View(form); TempData["Message"] = "Connection Error"; } catch (Exception ex) { // log exception for other exceptions logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = View(form); TempData["Message"] = "Error Try Again"; } return(response); }
public ActionResult WrittingDetails(long writtingId) { // creating response variable ActionResult response; // viewing by writting id and mapping the writtings WrittingsDO writtings = WrittingsDataAccess.ViewWrittingsById(writtingId); Writtings detailWrittings = mapper.MapDoToPo(writtings); // writtingid variable long WrittingID = detailWrittings.WrittingId; try { //check if valid if (writtingId > 0) { // if valid view details response = View(detailWrittings); } else { // if not valid redirect response = RedirectToAction("AllWrittings", "Writtings"); } } catch (SqlException Sqlex) { //Log exception for sql logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Sqlex); response = View(writtings); TempData["Message"] = "Connection Error"; } catch (Exception ex) { // log exception for other exceptions logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = View(writtings); TempData["Message"] = "Error Try Again"; } return(response); }
public ActionResult UpdateWrittings(Writtings form) { // response variables ActionResult response; try { // checking to see if valid if (ModelState.IsValid) { //updates wordcount form.WordCount = logic.CountWords(form.Content); // mapping the updated writting PO to DO WrittingsDO writtingsDO = mapper.MapPoToDo(form); WrittingsDataAccess.UpdateWrittings(writtingsDO); // redirect response = RedirectToAction("AllWrittings", "Writtings"); } else { response = View(form); } } catch (SqlException Sqlex) { //Log exception for sql logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Sqlex); response = View(form); TempData["Message"] = "Connection Error"; } catch (Exception ex) { // log exception for other exceptions logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = View(form); TempData["Message"] = "Error Try Again"; } return(response); }
/// <summary> /// DO to PO /// </summary> /// <param name="from"></param> /// <returns> out information</returns> public Writtings MapDoToPo(WrittingsDO from) { Writtings to = new Writtings(); to.WrittingId = from.WrittingId; to.Username = from.Username; to.Title = from.Title; to.DatePublished = from.DatePublished; // creates a summory of the content to.Content = from.Content; if (from.Content.Length > 64) { to.Blurb = from.Content.Substring(0, 64) + "..."; } else { to.Blurb = from.Content; } to.UserId = from.UserId; to.WordCount = from.WordCount; return(to); }