Пример #1
0
        public async Task <IActionResult> ReviewArtistActivity(int artistActivityId, bool isApproved)
        {
            var artistActivity = await moderatorRepository.GetArtistActivityToReview(artistActivityId);

            if (isApproved)
            {
                var modId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
                artistActivity.ApprovedByModeratorId = modId;
                var artist = await appRepository.GetArtist(artistActivity.ArtistId);

                artistActivity.IsApproved = true;
                var dateOfBirth = artist.DateOfBirth;
                mapper.Map(artistActivity, artist);
                if (artistActivity.DateOfBirth == null)
                {
                    artist.DateOfBirth = dateOfBirth;
                }
                if (await appRepository.SaveAll())
                {
                    return(Ok());
                }
                return(BadRequest("Unable to save changes"));
            }
            appRepository.Delete(artistActivity);
            if (await appRepository.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("Unable to save changes"));
        }
Пример #2
0
        public async Task <IActionResult> ReviewMovieActivity(int movieActivityId, bool isApproved)
        {
            var movieActivity = await moderatorRepository.GetMovieActivityToReview(movieActivityId);

            if (isApproved)
            {
                var modId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
                movieActivity.ApprovedByModeratorId = modId;
                var movie = await appRepository.GetMovie(movieActivity.MovieId);

                movieActivity.IsApproved = true;
                var releaseDate = movie.ReleaseDate;
                mapper.Map(movieActivity, movie);
                if (movieActivity.ReleaseDate == null)
                {
                    movie.ReleaseDate = releaseDate;
                }
                if (await appRepository.SaveAll())
                {
                    return(Ok());
                }
                return(BadRequest("Unable to save changes"));
            }
            appRepository.Delete(movieActivity);
            if (await appRepository.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("Unable to save changes"));
        }
Пример #3
0
        public async Task <IActionResult> ReviewMoviePhotoDeleteRequest(int id, bool isApproved)
        {
            var deleteRequest = await moderatorRepository.GetPhotoDeleteRequest(id);

            if (deleteRequest == null)
            {
                return(BadRequest("The request does not exist"));
            }
            if (isApproved)
            {
                var photo = await appRepository.GetPhoto(deleteRequest.PhotoId);

                if (photo.IsMain)
                {
                    return(BadRequest("Cannot delete main photo. Change the main photo before deleting this."));
                }
                if (await DeletePhoto(photo))
                {
                    return(Ok());
                }
                return(BadRequest("Unable to process request"));
            }
            appRepository.Delete(deleteRequest);
            if (await appRepository.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("Unable to process request"));
        }
Пример #4
0
        public ActionResult DeleteAgent(int id)
        {
            var agents  = _appRepository.GetAgents();
            var agent   = agents.FirstOrDefault(x => x.Id == id);
            var adverts = _appRepository.GetAdvertsByAgent(agent.Id);

            foreach (var item in adverts)
            {
                _appRepository.Delete(item);
            }
            _appRepository.Delete(agent);
            _appRepository.SaveAll();
            return(Ok());
        }
Пример #5
0
        public async Task <IActionResult> DeleteUser(string userType, int userId)
        {
            switch (userType)
            {
            case UserTypes.Renter:
                var renterToDelete = new Renter {
                    UserId = userId
                };
                _apprepo.Delete(renterToDelete);
                if (await _apprepo.SaveAll())
                {
                    return(Ok(renterToDelete));
                }
                return(BadRequest("Problem deleting user"));

            case UserTypes.Owner:
                var ownerToDelete = new Owner {
                    UserId = userId
                };
                _apprepo.Delete(ownerToDelete);
                if (await _apprepo.SaveAll())
                {
                    return(Ok(ownerToDelete));
                }
                return(BadRequest("Problem deleting user"));

            case UserTypes.Driver:
                var driverToDelete = new Driver {
                    UserId = userId
                };
                _apprepo.Delete(driverToDelete);
                if (await _apprepo.SaveAll())
                {
                    return(Ok(driverToDelete));
                }
                return(BadRequest("Problem deleting user"));

            case UserTypes.Admin:
                var adminToDelete = new Admin {
                    UserId = userId
                };
                _apprepo.Delete(adminToDelete);
                if (await _apprepo.SaveAll())
                {
                    return(Ok(adminToDelete));
                }
                return(BadRequest("Problem deleting user"));
            }
            return(BadRequest("Error deleting user"));
        }
Пример #6
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var user = await _repo.GetUser(userId);

            if (!user.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _repo.GetPhoto(id);

            if (photoFromRepo.IsMain)
            {
                if (user.Photos.Count > 1)
                {
                    var newMainPhoto = user.Photos.FirstOrDefault(p => p.Id != id);
                    newMainPhoto.IsMain = true;
                }
            }
            // return BadRequest("You cannot delete your main photo");

            if (photoFromRepo.PublicId != null)
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);

                var result = _cloudinary.Destroy(deleteParams);

                if (result.Result == "ok")
                {
                    _repo.Delete(photoFromRepo);
                }
            }
            else
            {
                _repo.Delete(photoFromRepo);
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete the photo"));
        }
        public async Task <IActionResult> ExitGroup(int userId, int groupId)
        {
            var currentUser = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (currentUser != userId)
            {
                return(Unauthorized());
            }

            var group = await _repo.GetGroup(groupId); // Verifica se o grupo existe

            if (group == null)
            {
                return(BadRequest("Grupo não existe"));
            }

            var userGroup = await _repo.GetUserGroup(userId, groupId); // Verifica se o usuario ja esta no grupo

            if (userGroup == null)
            {
                return(BadRequest("Você não pertence a este grupo"));
            }

            _repo.Delete <UsuariosGrupos>(userGroup);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Falha ao sair do grupo"));
        }
Пример #8
0
        public async Task <IActionResult> DeleteMessage(int id, int userId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var messageFromRepo = await _repo.GetMessage(id);

            if (messageFromRepo.SenderId == userId)
            {
                messageFromRepo.SenderDeleted = true;
            }

            if (messageFromRepo.RecipientId == userId)
            {
                messageFromRepo.RecipientDeleted = true;
            }

            if (messageFromRepo.SenderDeleted && messageFromRepo.RecipientDeleted)
            {
                _repo.Delete(messageFromRepo);
            }

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception("Error deleting the message");
        }
Пример #9
0
 public Result Delete(string id)
 {
     try
     {
         var rlt = UnitOfWorkService.Execute(() => _repo.Delete(id));
         if (!rlt)
         {
             return new Result {
                        Status = false, Message = "数据库操作失败"
             }
         }
         ;
         var url  = _configuration.GetValue("WebApi:url", "http://localhost:15002/sync");
         var http = _hxHttpClientFactory.CreateHttpClient();
         http.SendAsync(url, Serializer.Serialize(new CusNotification {
             Method = 13, Body = id
         }));
         Logger.Info($"app同步结果del:{id}");
         return(new Result {
             Status = true
         });
     }
     catch (Exception ex)
     {
         Logger.Error("delete app error", ex);
         return(new Result {
             Status = false, Message = "内部服务器错误"
         });
     }
 }
        public ActionResult DeleteAdvert(int id)
        {
            var advert = _appRepository.GetAdvertById(id);

            _appRepository.Delete(advert);
            _appRepository.SaveAll();
            return(Ok());
        }
Пример #11
0
        public async Task <IActionResult> Delete([FromForm] PostDeleteModel model)
        {
            try
            {
                if (this.ValidRoleForAction(_context, _auth, new string[] { "Student", "Teacher", "Editor" }))
                {
                    AppIdentityUser currentuser = this.GetLoggedUser(_auth, _context);
                    if (ModelState.IsValid)
                    {
                        if (model.PostUserId == currentuser.Id || await _auth.CheckUserRole(currentuser, "Editor"))
                        {
                            Book item = await _context.GetByIdAsync <Book>(x => x.Id == model.PostId);

                            if (item != null)
                            {
                                _context.Delete(item);
                                bool result = await _context.SaveAll();

                                if (result == true)
                                {
                                    return(Ok("Success"));
                                }
                                else
                                {
                                    return(BadRequest("Model cannot be  deleted"));
                                }
                            }
                            else
                            {
                                return(NotFound("Model not found"));
                            }
                        }
                        return(BadRequest($"{currentuser.Name}, you don't have a permission"));
                    }
                    return(BadRequest("Model is not valid"));
                }
                return(Forbid());
            }
            catch (Exception ex)
            {
                var arguments = this.GetBaseData(_context, _auth);
                _logger.LogException(ex, arguments.Email, arguments.Path);
                return(BadRequest($"{ex.GetType().Name} was thrown."));
            }
        }
Пример #12
0
 public async Task <IActionResult> DeleteUser(User userToDelete)
 {
     _apprepo.Delete(userToDelete);
     if (await _apprepo.SaveAll())
     {
         return(Ok(userToDelete));
     }
     return(BadRequest("Problem deleting user"));
 }
Пример #13
0
 public bool Delete(Category id)
 {
     if (id != null)
     {
         appRepository.Delete(id);
         return(true);
     }
     return(false);
 }
        public ActionResult Delete(string ktKod, int id)
        {
            var data = _appRepository.GetIcerikById(ktKod, id);

            if (data == null)
            {
                return(Ok(_ControllersHelper.notfound(info: id)));
            }

            _appRepository.Delete(data); ////////////////////////////////////////

            if (_appRepository.SaveAll())
            {
                return(Ok(data));
            }
            else
            {
                return(BadRequest(id + " başarısız?!"));
            }
        }
Пример #15
0
        public async Task <IActionResult> LikePost(int userId, int postId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            if (await _repo.GetPost(postId) == null)
            {
                return(NotFound());
            }

            var like = await _repo.GetLike(userId, postId);

            if (like != null)
            {
                return(BadRequest("You already liked this post!"));
            }

            var dislike = await _repo.GetDislike(userId, postId);

            if (dislike != null)
            {
                _repo.Delete <Dislike>(dislike);
            }

            like = new Like
            {
                LikerId = userId,
                PostId  = postId
            };

            _repo.Add <Like>(like);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to like post!"));
        }
        [Route("delete/{id}")] // böyle daha açık
        public IActionResult Delete(int id)
        {
            var data = _appRepository.GetDerslerById(id);

            if (data == null)
            {
                return(Ok(_ControllersHelper.notfound(info: id)));
            }

            _appRepository.Delete(data); ////////////////////////////////////////

            var res = _appRepository.SaveAll();

            if (res.OK)
            {
                return(Ok(data));
            }
            else
            {
                return(BadRequest(id + " başarısız?! " + res.ERR));
            }
        }
Пример #17
0
        public async Task <IActionResult> ReviewMovieRole(int id, bool isApproved)
        {
            var movieRole = await moderatorRepository.GetMovieRoleToReview(id);

            if (movieRole == null)
            {
                return(BadRequest("The movie role does not exist"));
            }
            if (!movieRole.IsArtistApproved)
            {
                return(BadRequest("You need to review the artist before you can review this role"));
            }
            if (!movieRole.IsMovieApproved)
            {
                return(BadRequest("You need to review the movie before you can review this role"));
            }
            if (isApproved)
            {
                var modId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
                movieRole.IsApproved = true;
                var firstActivity = movieRole.ActivityLogs.FirstOrDefault();
                firstActivity.IsApproved            = true;
                firstActivity.ApprovedByModeratorId = modId;
                foreach (var activity in movieRole.ActivityLogs)
                {
                    activity.IsMovieRoleApproved = true;
                }
            }
            else
            {
                appRepository.Delete(movieRole);
            }
            if (await appRepository.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("Unable to review this movie role"));
        }
Пример #18
0
        public bool Invoke(int appId)
        {
            var appToDelete = appRepository.GetById(appId);

            if (appToDelete == null)
            {
                return(false);
            }

            appRepository.Delete(appToDelete);
            appRepository.Save();

            return(true);
        }
Пример #19
0
        public async Task <IActionResult> DeleteRoleType(int id)
        {
            var roleType = await appRepository.GetRoleType(id);

            if (roleType == null)
            {
                return(BadRequest("The role type does not exist"));
            }
            appRepository.Delete(roleType);
            if (await appRepository.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("Unable to Delete Role Type"));
        }
Пример #20
0
        public async Task <IResultModel> Update(UserUpdateModel model)
        {
            var entity = await _userRepository.Get(model.Id);

            if (entity == null)
            {
                return(ResultModel.Failed("用户不存在!"));
            }
            if (entity.IsLock)
            {
                return(ResultModel.Failed("用户锁定,不允许修改"));
            }
            var user   = _mapper.Map(model, entity);
            var exists = await Exists(user);

            if (!exists.IsSuccess)
            {
                return(exists);
            }
            await _userRepository.Update(user);

            var userRoles = _userRoleRepository.Query(p => p.UserId == model.Id);

            if (userRoles.Any())
            {
                await _userRoleRepository.Delete(userRoles.Select(p => p.Id).ToArray());
            }
            if (model.Roles != null && model.Roles.Any())
            {
                var userRoleList = model.Roles.Select(m => new UserRoleEntity {
                    UserId = user.Id, RoleId = m
                }).ToList();
                await _userRoleRepository.Insert(userRoleList.ToArray());
            }
            return(ResultModel.Success());
        }
Пример #21
0
        public async Task <IActionResult> DeleteStaff(int id)
        {
            var staffToDelete = await _appRepository.FindStaff(id);

            if (staffToDelete == null)
            {
                return(NotFound());
            }

            _appRepository.Delete(staffToDelete);

            await _unitOfWork.SaveAll();

            return(NoContent());
        }
Пример #22
0
        public ActionResult DeleteCar(int id)
        {
            var car = _appRepository.GetCarById(id);

            try {
                _appRepository.Delete(car);
                if (!_appRepository.SaveAll())
                {
                    return(BadRequest());
                }
            } catch (Exception) {
                throw;
            }
            return(Ok(car));
        }
Пример #23
0
        public async Task <IActionResult> DeleteQualification(int id)
        {
            var qualToDelete = await _appRepository.FindQualification(id);

            if (qualToDelete == null)
            {
                return(NotFound());
            }

            _appRepository.Delete(qualToDelete);

            await _unitOfWork.SaveAll();

            return(NoContent());
        }
Пример #24
0
        public async Task <IResultModel> Delete(Guid id)
        {
            var user = await _userRepository.Get(id);

            if (user == null || user.IsDeleted)
            {
                return(ResultModel.Failed("用户不存在"));
            }
            if (user.IsLock)
            {
                return(ResultModel.Failed("用户锁定,不允许删除"));
            }
            var result = await _userRepository.Delete(id);

            return(ResultModel.Success(result));
        }
Пример #25
0
        public async Task <IActionResult> DeleteEmpoyee(int id)
        {
            var EmployeeFromRepo = _repo.GetEmployee(id);

            if (EmployeeFromRepo != null)
            {
                _repo.Delete(EmployeeFromRepo.Result);
                var result = await _repo.SaveAll();

                return(Ok("Employee Deleted!"));
            }
            else
            {
                return(BadRequest("Employee doesn't exist!"));
            }
        }
Пример #26
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var home = await _appRepo.Search(x => x.Id == request.Id);

                if (home == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { home = "Care Home could not be found." });
                }

                _appRepo.Delete(home);

                if (await _appRepo.SaveAllAsync())
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving changes");
            }
Пример #27
0
        public IActionResult DeleteApp(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(Json(false));
            }

            var app = _appRepository.Get(id);

            if (app == null)
            {
                return(Json(false));
            }

            _appRepository.Delete(app);
            _memoryCache.Remove($"app_{app.Id}");

            return(Json(true));
        }
Пример #28
0
        public ActionResult DeleteModel([FromRoute] int id)
        {
            var model = _appRepository.GetModelById(id);

            if (model == null)
            {
                return(NotFound());
            }
            try {
                _appRepository.Delete(model);
                if (_appRepository.SaveAll())
                {
                    return(Ok(model));
                }
            } catch (Exception) {
                throw;
            }
            return(BadRequest());
        }
Пример #29
0
        public ActionResult DeleteBrand(int id)
        {
            var brand = _appRepository.GetBrandById(id);

            if (brand == null)
            {
                return(NotFound());
            }
            try {
                _appRepository.Delete(brand);
                if (_appRepository.SaveAll())
                {
                    return(Ok(brand));
                }
            } catch (Exception) {
                throw;
            }
            return(BadRequest("An error occured"));
        }
Пример #30
0
        public async Task <IActionResult> Delete(int id)
        {
            if (id < 1)
            {
                return(BadRequest("Id hasn't been provided"));
            }

            var home = await _appRepo.GetByIdAsync(id);

            if (home == null)
            {
                return(NotFound(new { error = $"No home could be found with id: {id}" }));
            }

            _appRepo.Delete(home);

            await _appRepo.SaveAllAsync();

            return(Ok($"Home with id: {id} has been removed."));
        }