public IActionResult Createhighlight(int id) { SucceedInfomation succeedinfomation = new SucceedInfomation(); // find postocntent first if found then Add it to the highlight table postcontent postcontentValue = _Context.postcontents.FirstOrDefault(x => x.postid == id); if (postcontentValue == null) { succeedinfomation.Issucceed = false; return(Ok(succeedinfomation)); } var checkhg = _Context.highlights.FirstOrDefault(x => x.postcontentid == postcontentValue.postcontentid); if (checkhg != null) { succeedinfomation.Issucceed = false; succeedinfomation.SucceedDetail = "duplicated content"; return(Ok(succeedinfomation)); } var Newhighlight = new highlight(); Newhighlight.postcontentid = postcontentValue.postcontentid; _Context.highlights.Add(Newhighlight); _Context.SaveChanges(); succeedinfomation.Issucceed = true; return(Ok(succeedinfomation)); }
public ActionResult Editpostcontent([FromForm] Updatepayload updatepayload) { SucceedInfomation succeedinfomation = new SucceedInfomation(); //find postcontent metadata and use this metada to obtain post id and content id postcontent postcontentvalue = _Context.postcontents.FirstOrDefault(x => x.postid == updatepayload.postid); // find post id post postvalue = _Context.posts.FirstOrDefault(x => x.postid == postcontentvalue.postid); // insert new imgurl if imgfile payload not null if (updatepayload.imgfile != null) { // remove old file but that come later if (updatepayload.imgfile.FileName.EndsWith(".jpg")) { postvalue.titleimgurl = _imgservice.SaveAsJPG(updatepayload.imgfile); } else if (updatepayload.imgfile.FileName.EndsWith(".png")) { postvalue.titleimgurl = _imgservice.SaveAsPng(updatepayload.imgfile); } } // insert new value of postitle postvalue.posttitle = updatepayload.posttitle; // find content id content contentvalue = _Context.contents.FirstOrDefault(x => x.contentid == postcontentvalue.contentid); // insert new value of content contentvalue.contentdetail = updatepayload.contentdetail; // the Update operation start here // _Context.posts.Update(postvalue); _Context.contents.Update(contentvalue); _Context.SaveChanges(); return(Ok(succeedinfomation)); }
public IActionResult createuser(UserPayload userpayload) { SucceedInfomation succeedinfomation = new SucceedInfomation(); if (userpayload.password.Length < 6) { succeedinfomation.Issucceed = false; succeedinfomation.SucceedDetail = "password must be atleast 6 character"; return(Ok(succeedinfomation)); } // find user if exist return false user finduser = _Context.users.FirstOrDefault(x => x.username == userpayload.username); if (finduser != null) { succeedinfomation.Issucceed = false; succeedinfomation.SucceedDetail = "username exited"; } //generate salt and hash SaltHashed salthashed = _authservice.provideSaltHashed(userpayload.password); user Newuser = new user() { username = userpayload.username, userfirstname = userpayload.userfirstname, userlastname = userpayload.userlastname, usersalt = salthashed.StrSalt, userhashed = salthashed.StrHashed, roleid = 2 }; _Context.users.Add(Newuser); _Context.SaveChanges(); return(Ok(succeedinfomation)); }
public async Task <ActionResult <SucceedInfomation> > updateuser(UserUpdatepayload userpl) { SucceedInfomation succeedinformation = new SucceedInfomation(); //new object of hashsalted SaltHashed salthashed = new SaltHashed(); user finduser = await _Context.users.FirstOrDefaultAsync(x => x.userid == userpl.userid); // if userpassword is not null then return a new value using service if (userpl.password != null) { salthashed = this._authservice.provideSaltHashed(userpl.password); finduser.usersalt = salthashed.StrSalt; finduser.userhashed = salthashed.StrHashed; } ; finduser.userfirstname = userpl.userfirstname; finduser.userlastname = userpl.userlastname; // if userpassword is null then retrun default value of hashed and salted _Context.users.Update(finduser); var result = await _Context.SaveChangesAsync(); succeedinformation.SucceedDetail = result.ToString(); return(Ok(succeedinformation)); }
public async Task <ActionResult <SucceedInfomation> > createpostcontent([FromForm] PostPayload postpayload) { SucceedInfomation succeedinformation = new SucceedInfomation(); post Newpost = new post() { posttitle = postpayload.posttitle }; if (postpayload.imgfile == null || postpayload.posttitle.Length < 3) { succeedinformation.Issucceed = false; succeedinformation.SucceedDetail = "Please complete the form"; return(Ok(succeedinformation)); } if (postpayload.imgfile.FileName.EndsWith(".jpg")) { Newpost.titleimgurl = await _imgservice.SaveFileJpg(postpayload.imgfile); } else if (postpayload.imgfile.FileName.EndsWith(".png")) { Newpost.titleimgurl = await _imgservice.SaveFilePng(postpayload.imgfile); } // else if(postpayload.imgfile.Length == 0) // { // succeedinformation.Issucceed = false; // succeedinformation.SucceedDetail = "file format invalide , pls use jpg or png"; // return Ok(succeedinformation); // } content Newcontent = new content() { contentdetail = postpayload.contentdetail }; _Context.posts.Add(Newpost); _Context.contents.Add(Newcontent); _Context.SaveChanges(); var Newposcontent = new postcontent() { postid = Newpost.postid, contentid = Newcontent.contentid, userid = postpayload.userid, categoryid = postpayload.categoryid, postcontentcreated = DateTime.UtcNow }; _Context.postcontents.Add(Newposcontent); _Context.SaveChanges(); return(succeedinformation); }
public IActionResult DeleteCategory(int id) { SucceedInfomation succeedinfomation = new SucceedInfomation(); category Newcategory = new category() { categoryid = id }; _Context.categories.Remove(Newcategory); var result = _Context.SaveChanges(); if (result == 0) { succeedinfomation.Issucceed = false; return(Ok(succeedinfomation)); } return(Ok(succeedinfomation)); }
public async Task <ActionResult <SucceedInfomation> > DeleteUser(int id) { SucceedInfomation succeedinformation = new SucceedInfomation(); user uservalue = await _Context.users.FirstOrDefaultAsync(x => x.userid == id); if (uservalue.roleid != 2) { succeedinformation.Issucceed = false; succeedinformation.SucceedDetail = "failed"; return(Ok(succeedinformation)); } _Context.users.Remove(uservalue); var result = await _Context.SaveChangesAsync(); succeedinformation.SucceedDetail = result.ToString(); succeedinformation.SucceedDetail = result.ToString(); return(Ok(succeedinformation)); }
public IActionResult updatecategory(category catepayload) { SucceedInfomation succeedinfomation = new SucceedInfomation(); category Newcategory = new category() { categoryid = catepayload.categoryid, categoryname = catepayload.categoryname }; _Context.categories.Update(Newcategory); var result = _Context.SaveChanges(); if (result == 0) { succeedinfomation.Issucceed = false; return(Ok(succeedinfomation)); } return(Ok(succeedinfomation)); }
public IActionResult CreateCategory([FromBody] CategoryPayload categorypayload) { SucceedInfomation succeedinfomation = new SucceedInfomation(); category Newcategory = new category() { categoryname = categorypayload.CategoryName }; _Context.categories.Add(Newcategory); var result = _Context.SaveChanges(); if (result == 0) { succeedinfomation.Issucceed = false; return(Ok(succeedinfomation)); } return(Ok(succeedinfomation)); }
public IActionResult deleteHighlight(int id) { SucceedInfomation succeedinfomation = new SucceedInfomation(); // find postocntent first if found then Add it to the highlight table postcontent postcontentValue = _Context.postcontents.FirstOrDefault(x => x.postid == id); var highlightValue = _Context.highlights.FirstOrDefault(x => x.postcontentid == postcontentValue.postcontentid); if (highlightValue == null) { succeedinfomation.Issucceed = false; return(Ok(succeedinfomation)); } var Newhighlight = new highlight(); _Context.highlights.Remove(highlightValue); _Context.SaveChanges(); succeedinfomation.Issucceed = true; return(Ok(succeedinfomation)); }
public async Task <ActionResult <SucceedInfomation> > post(int id) { SucceedInfomation succeedinformation = new SucceedInfomation(); postcontent postcontenvalue = await _Context.postcontents.FirstOrDefaultAsync(x => x.postid == id); post postvalue = new post() { postid = postcontenvalue.postid }; content contentvalue = new content() { contentid = postcontenvalue.contentid }; _Context.posts.Remove(postvalue); _Context.contents.Remove(contentvalue); var result = await _Context.SaveChangesAsync(); succeedinformation.SucceedDetail = result.ToString(); return(Ok(succeedinformation)); }