示例#1
0
        public void Delete_Ok_Test()
        {
            var picture = _context.Pictures.Take(10).ToList().Last();

            _pictureOperations.DeleteAsync(picture.Id).Wait();

            using (var cntxt = new HobbyContext())
            {
                Assert.IsNull(cntxt.Pictures.FirstOrDefault(p => p.Id == picture.Id));
            }
        }
示例#2
0
        public async Task <IHttpActionResult> DeleteAsync(int id)
        {
            if (User.IsInRole("RegisteredUser"))
            {
                var canDelete = await _pictureOperations.CheckPermission(User.Identity.Name, id);

                if (!canDelete)
                {
                    return(this.Result403("Вы не можете удалять чужие аватарки"));
                }
            }

            await _pictureOperations.DeleteAsync(id);

            return(Ok("Deleted"));
        }