Esempio n. 1
0
        public void Delete_Ok_Test()
        {
            var review = _context.Reviews.Take(10).ToList().Last();

            _reviewOperations.DeleteAsync(review.Id).Wait();

            using (var cntxt = new HobbyContext())
            {
                Assert.IsNull(cntxt.Reviews.FirstOrDefault(r => r.Id == review.Id));
            }
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> Delete(int id)
        {
            try
            {
                var review = await _reviewOperations.GetAsync(id);

                if (review == null)
                {
                    return(this.Result404("This review is not found"));
                }
                var checkRightsResult = CheckPermission(review);
                if (checkRightsResult != null)
                {
                    return(checkRightsResult);
                }

                await _reviewOperations.DeleteAsync(id);

                return(Ok("Deleted"));
            }
            catch (Exception ex)
            {
                ErrorLogger.Log("CANNOT DELETE REVIEW", ex);
                throw;
            }
        }
Esempio n. 3
0
        public async Task DeleteAsync(string email)
        {
            var user = _context.Users.FirstOrDefault(u => u.Email == email);

            Contracts.Assert(user != null);

            var reviews = await _reviewsOperations.GetByUserEmailAsync(user.Email);

            foreach (var review in reviews)
            {
                await _reviewsOperations.DeleteAsync(review.Id);
            }
            var userVoices = await _voiceOperations.GetUserVoices(user.Id);

            foreach (var userVoice in userVoices)
            {
                await _voiceOperations.DeleteVoiceAsync(userVoice.Id);
            }

            _context.Users.Remove(user);
            await _context.SaveChangesAsync();
        }