Пример #1
0
        internal Blg GetById(int id)
        {
            Blg original = _repo.Get(id);

            if (original == null)
            {
                throw new Exception("Invalid Id");
            }
            return(original);
        }
Пример #2
0
        internal string Delete(int id, string userId)
        {
            Blg original = GetById(id);

            if (original.CreatorId != userId)
            {
                throw new Exception("Not for u!");
            }
            _repo.Remove(id);
            return("Deleted!!!");
        }
Пример #3
0
        internal int Create(Blg newBlg)
        {
            string sql = @"
      INSERT INTO blgs
      (creatorId, title, body, isPublished)
      VALUES
      (@CreatorId, @Title, @Body, @IsPublished);
      SELECT LAST_INSERT_ID();";

            return(_db.ExecuteScalar <int>(sql, newBlg));
        }
Пример #4
0
        internal Blg Edit(Blg editBlg, string userId)
        {
            Blg original = GetById(editBlg.Id);

            if (original.CreatorId != userId)
            {
                throw new Exception("Dont do anything Shiwani!");
            }
            editBlg.Title       = editBlg.Title == null ? original.Title : editBlg.Title;
            editBlg.Body        = editBlg.Body == null ? original.Body : editBlg.Body;
            editBlg.IsPublished = editBlg.IsPublished == false? original.IsPublished : editBlg.IsPublished;
            return(_repo.Edit(editBlg));
        }
Пример #5
0
        internal Blg Edit(Blg editBlg)
        {
            string sql = @"
        UPDATE blgs
        SET
        title= @Title,
        body= @Body,
        isPublished = @IsPublished
        WHERE id = @Id;
        ";

            _db.Execute(sql, editBlg);
            return(editBlg);
        }
Пример #6
0
        public async Task <ActionResult <Blg> > Edit([FromBody] Blg editBlg, int id)
        {
            try{
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                editBlg.Id      = id;
                editBlg.Creator = userInfo;
                return(Ok(_bs.Edit(editBlg, userInfo.Id)));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Пример #7
0
        public async Task <ActionResult <Blg> > Post([FromBody] Blg newBlg)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                newBlg.CreatorId = userInfo.Id;
                Blg created = _bs.Create(newBlg);
                created.Creator = userInfo;
                return(Ok(created));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Пример #8
0
        public async Task <ActionResult <Blg> > Get(int id)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                {
                    Blg blg = _bs.GetById(id);
                    return(Ok(blg));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Пример #9
0
 internal Blg Create(Blg newBlg)
 {
     newBlg.Id = _repo.Create(newBlg);
     return(newBlg);
 }