public IActionResult ReloadClientProblemImage(long clientID, long problemID, long imageID) { var user = UserService.Get(long.Parse(User.Identity.Name)); if (user == null) { return(NotFound(new ResponseModel { Success = false, Message = "Пользователь не найден" })); } var specialist = SpecialistService.GetSpecialistFromUser(user); if (specialist == null) { return(NotFound(new ResponseModel { Success = false, Message = "Специалист не найден" })); } var client = UserService.Get(clientID); if (client == null) { return(NotFound(new ResponseModel { Success = false, Message = "Клиент не найден" })); } var problem = ProblemService.Get(problemID); if (problem == null) { return(NotFound(new ResponseModel { Success = false, Message = "Проблема не найдена" })); } if (problem.User != client) { return(BadRequest(new ResponseModel { Success = false, Message = "Ошибка доступа" })); } var image = ProblemImageService.Get(imageID); if (image == null) { return(NotFound(new ResponseModel { Success = false, Message = "Образ не найден" })); } var session = SessionService.GetCurrentSession(problem); if (session == null) { return(NotFound(new ResponseModel { Success = false, Message = "Активная сессия не найдена" })); } if (session.Problem != problem) { return(BadRequest(new ResponseModel { Success = false, Message = "Ошибка доступа" })); } image.IsHidden = false; ProblemImageService.Update(image); var problemImages = ProblemImageService.GetProblemImages(problem) .Select(x => new ProblemImageViewModel(x)) .ToList(); return(Ok(new DataResponse <List <ProblemImageViewModel> > { Data = problemImages })); }
public IActionResult EditClientProblemImage([FromBody] CreateUpdateProblemImageRequest request, long clientID, long problemID, long imageID) { var user = UserService.Get(long.Parse(User.Identity.Name)); if (user == null) { return(NotFound(new ResponseModel { Success = false, Message = "Пользователь не найден" })); } var specialist = SpecialistService.GetSpecialistFromUser(user); if (specialist == null) { return(NotFound(new ResponseModel { Success = false, Message = "Специалист не найден" })); } var client = UserService.Get(clientID); if (client == null) { return(NotFound(new ResponseModel { Success = false, Message = "Клиент не найден" })); } var problem = ProblemService.Get(problemID); if (problem == null) { return(NotFound(new ResponseModel { Success = false, Message = "Проблема не найдена" })); } if (problem.User != client) { return(BadRequest(new ResponseModel { Success = false, Message = "Ошибка доступа" })); } var session = SessionService.GetCurrentSession(problem); if (session == null) { return(NotFound(new ResponseModel { Success = false, Message = "Активная сессия не найдена" })); } if (session.Problem != problem) { return(BadRequest(new ResponseModel { Success = false, Message = "Ошибка доступа" })); } var problemImage = ProblemImageService.Get(imageID); if (problemImage == null) { return(NotFound(new ResponseModel { Success = false, Message = "Образ не найден" })); } if (request.Title != problemImage.Title) { problemImage.Title = request.Title; } if (request.Emotion != problemImage.Emotion) { problemImage.Emotion = request.Emotion; } if (request.Location != problemImage.Location) { problemImage.Location = request.Location; } if (request.Characteristic != problemImage.Characteristic) { problemImage.Characteristic = request.Characteristic; } if (request.IsMine != problemImage.IsMine) { problemImage.IsMine = request.IsMine; } if (request.IsIDo != problemImage.IsIDo) { problemImage.IsIDo = request.IsIDo; } if (request.IsForever != problemImage.IsForever) { problemImage.IsForever = request.IsForever; } if (request.LikeScore != problemImage.LikeScore) { problemImage.LikeScore = request.LikeScore; } long parentImageID = 0; if (problemImage.ParentImage != null) { parentImageID = problemImage.ParentImage.ID; } if (request.ParentImageID != 0 && request.ParentImageID != parentImageID) { var newParentImage = ProblemImageService.Get(request.ParentImageID); if (newParentImage == null) { return(NotFound(new ResponseModel { Success = false, Message = "Зависимость не найдена" })); } problemImage.ParentImage = newParentImage; } else if (request.ParentImageID == 0) { problemImage.ParentImage = null; } ProblemImageService.Update(problemImage); var problemImages = ProblemImageService.GetProblemImages(problem) .Select(x => new ProblemImageViewModel(x)) .ToList(); return(Ok(new DataResponse <List <ProblemImageViewModel> > { Data = problemImages })); }