internal Blg GetById(int id) { Blg original = _repo.Get(id); if (original == null) { throw new Exception("Invalid Id"); } return(original); }
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!!!"); }
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)); }
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)); }
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); }
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)); } }
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)); } }
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)); } }
internal Blg Create(Blg newBlg) { newBlg.Id = _repo.Create(newBlg); return(newBlg); }