//Create Post and update into DB public Response DBCreatePost(string postauthor, int postcategoryid, string posttitle, string postdescription, DateTime postdate) { tblpost post = new tblpost(); //byte allfiles = byte.Join(",", postfiles); using (ivimessageboardEntities entities = new ivimessageboardEntities()) { post.postauthor = postauthor; post.posttitle = posttitle; post.postcategoryid = postcategoryid; post.postdescription = postdescription; post.postdate = postdate; //post.postfileuploaded = allfiles; try { entities.tblposts.Add(post); entities.SaveChanges(); response.isSuccess = true; return(response); } catch (Exception ex) { TapErrortoDB(entities, ex.ToString(), "DBUpdates", "Createpost"); response.isSuccess = false; return(response); } } }
//Add replies to Post and update into DB public Response addReplytoPost(int postid, string replyauthor, string replydescription, string replydate) { tblpostreply replypost = new tblpostreply(); using (ivimessageboardEntities entities = new ivimessageboardEntities()) { replypost.idreplyparent = postid; replypost.postreplyauthor = replyauthor; replypost.postreplydescription = replydescription; replypost.postreplydate = replydate; try { entities.tblpostreplies.Add(replypost); var replycount = (from item in entities.tblposts.ToList().AsEnumerable() where item.idposts == postid select item).FirstOrDefault(); replycount.postreplies = ((replycount.postreplies == null) ? 0 : replycount.postreplies) + 1; entities.SaveChanges(); response.isSuccess = true; return(response); } catch (Exception ex) { TapErrortoDB(entities, ex.ToString(), "DBUpdates", "addReplytoPost"); response.isSuccess = false; return(response); } } }
public void TapErrortoDB(ivimessageboardEntities DBentities, string errortext, string classname, string methodname) { try { tblError error = new tblError(); error.ErrorText = errortext; error.ErrorClassName = classname; error.ErrorMethodName = methodname; DBentities.tblErrors.Add(error); DBentities.SaveChanges(); } catch (Exception ex) { } }
//Create Category and update into DB public Response CreateCategory(string CategoryName) { tblcategory category = new tblcategory(); using (ivimessageboardEntities entities = new ivimessageboardEntities()) { category.CategoryName = CategoryName; try { entities.tblcategories.Add(category); entities.SaveChanges(); response.isSuccess = true; return(response); } catch (Exception ex) { TapErrortoDB(entities, ex.ToString(), "DBUpdates", "CreateCategory"); response.isSuccess = false; return(response); } } }
//Check if Security Question is correct or not in DB public void updateSecurityQuestion(string useremail, string securityquestion, string securityanswer) { tblUserSecurity tblUserSecurity = new tblUserSecurity(); using (ivimessageboardEntities entities = new ivimessageboardEntities()) { try { if (securityquestion.ToLower() != "allquestions") { tblUserSecurity.UserEmail = useremail; tblUserSecurity.UserSecurityQuestion = securityquestion; tblUserSecurity.UserSecurityAnswer = securityanswer; entities.tblUserSecurities.Add(tblUserSecurity); entities.SaveChanges(); } } catch (Exception ex) { TapErrortoDB(entities, ex.ToString(), "DBUpdates", "updateSecurityQuestion"); } } }