Exemple #1
0
        public async Task DeleteAdoptBookRequest(AdoptBookRequestForDelete adoptBookRequest)
        {
            var currentUser = _currentUserService.UserEmail;
            var user        = await _userManager.FindByEmailAsync(currentUser);

            string type = "";

            if (adoptBookRequest.Type == "Book")
            {
                type = "Book";
                var bookOrder = await _bookOrderRepository.GetByIdAsync(adoptBookRequest.Id);

                if (bookOrder.Status != OrderStatus.Pending)
                {
                    throw new ArgumentException("Order is diclined or approved");
                }
                if (bookOrder.UserId != user.Id)
                {
                    throw new ArgumentException("You can not delete this order");
                }
                await _bookOrderService.Delete(adoptBookRequest.Id);
            }
            if (adoptBookRequest.Type == "Adopt")
            {
                type = "Adopt";
                var adoptOrder = await _adoptOrderRepository.GetByIdAsync(adoptBookRequest.Id);

                if (adoptOrder.Status != OrderStatus.Pending)
                {
                    throw new ArgumentException("Order is diclined or approved");
                }
                if (adoptOrder.UserId != user.Id)
                {
                    throw new ArgumentException("You can not delete this order");
                }
                await _adoptOrderService.Delete(adoptBookRequest.Id);
            }

            var admins = await _userManager.GetUsersInRoleAsync("SuperAdmin");

            foreach (var admin in admins)
            {
                await _emailHelper.GetDataAndSendAsync(admin.Email, "DeleteAdoptBookRequestTemplate", "DeleteAdoptBookRequestSubject", $"{user.Email}", type, "link");
            }
        }