Exemple #1
0
        internal ViewModelKeep GetById(string profileId, int keepId)
        {
            _repo.AddView(keepId);
            ViewModelKeep original = _repo.GetById(keepId);

            if (original == null)
            {
                throw new Exception("Invalid Id");
            }
            return(original);
        }
        internal ViewModelKeep Edit(ViewModelKeep editKeep)
        {
            string sql = @"
            UPDATE keeps
            SET
            name = @Name,
            description = @Description,
            img = @Img
            WHERE id = @Id;";

            _db.Execute(sql, editKeep);
            return(editKeep);
        }
Exemple #3
0
        internal object Delete(int keepId, string userId)
        {
            ViewModelKeep original = _repo.GetById(keepId);

            if (original == null)
            {
                throw new Exception("Invalid Id");
            }
            if (original.CreatorId != userId)
            {
                throw new Exception("Access Denied. This is not yours");
            }
            _repo.Remove(keepId);
            return("Succesfully Delorted");
        }
        public async Task <ActionResult <ViewModelKeep> > Edit(int id, [FromBody] ViewModelKeep editKeep)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                editKeep.CreatorId = userInfo.Id;
                editKeep.Creator   = userInfo;
                editKeep.Id        = id;
                return(Ok(_ks.Edit(editKeep, userInfo.Id)));
            }
            catch (System.Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemple #5
0
        internal ViewModelKeep Edit(ViewModelKeep editKeep, string id)
        {
            ViewModelKeep original = _repo.GetById(editKeep.Id);

            if (original == null)
            {
                throw new Exception("Invalid Id");
            }
            if (original.CreatorId != id)
            {
                throw new Exception("Access Denied, this is not yours");
            }
            editKeep.Name        = editKeep.Name == null ? original.Name : editKeep.Name;
            editKeep.Description = editKeep.Description == null ? original.Description : editKeep.Description;
            editKeep.Img         = editKeep.Img == null ? original.Img : editKeep.Img;
            return(_repo.Edit(editKeep));
        }