Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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));
        }