public async Task <IActionResult> GetPublicMapPinById(Guid id) { try { ProblemPin problemPin = await publicPinServiceCRUD.GetPublicPinById(id); if (problemPin == null) { logger.LogInformation($"GetPublicMapPinById dont found Id: {id}"); return(NotFound(new ResponseDTO() { Message = "Пин не найден", Status = false })); } ResponseDTO answer = new ResponseDTO() { Status = true }; return(Ok(new { problemPin, answer })); } catch (ObjectNotFoundException ex) { logger.LogError(ex.Message); return(StatusCode(404, new ResponseDTO() { Message = "Пин не найден", Status = false })); } catch (Exception ex) { logger.LogError(ex.Message); return(StatusCode(500, false)); } }
public async Task <IActionResult> EditPublicPin(Guid Id, [FromBody] ProblemPin problemPin) { try { if (!ModelState.IsValid) { return(BadRequest()); } ResponseDTO answer = await publicPinServiceCRUD.EditPublicPin(Id, problemPin); return(Ok(answer)); } catch (ObjectNotFoundException ex) { logger.LogError(ex.Message); return(StatusCode(404, new ResponseDTO() { Message = "Пин не найден", Status = false })); } catch (Exception ex) { logger.LogError(ex.Message); return(StatusCode(500, new ResponseDTO() { Message = "На данный момент на стороне сервера ошибка сообщите администратору", Status = false })); } }
public async Task <ResponseDTO> ModerationAcceptPin(AcceptDTO acceptDTO, Moderator moderator) { //Remove from Moderation database table ProblemPin foundedPin = await moderatePinContext.ModerateProblemPins.Include(problemPin => problemPin.Images).FirstOrDefaultAsync(pins => pins.Id == acceptDTO.Id); moderatePinContext.ModerateProblemPins.Remove(foundedPin); await moderatePinContext.SaveChangesAsync(); // Add to Public database table foundedPin.ModeratorId = acceptDTO.ModeratorId; await publicPinContext.ProblemPins.AddAsync(foundedPin); int count = await publicPinContext.SaveChangesAsync(); if (count > 0) { Moderator newModerator = moderator; newModerator.ModeratedPinsCount += 1; moderatePinContext.Entry(moderator).CurrentValues.SetValues(newModerator); int countModerator = await moderatePinContext.SaveChangesAsync(); if (countModerator > 0) { cache.Set(newModerator.Id, newModerator, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(5))); } cache.Set(foundedPin.Id, foundedPin, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(5))); } return(new ResponseDTO() { Message = "Пин успешно прошёл модерацию и добавлен в публичную базу", Status = true }); }
public async Task <ResponseDTO> EditModerationPin(ProblemPin foundedPin, ProblemPinDTO newModerateProblemPin) { moderatePinContext.Entry(foundedPin).CurrentValues.SetValues(newModerateProblemPin); int count = await moderatePinContext.SaveChangesAsync(); if (count > 0) { cache.Set(foundedPin.Id, foundedPin, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(5))); } return(new ResponseDTO() { Message = "Пин изменён успешно", Status = true }); }
public async Task <ProblemPin> GetModerationPinById(Guid id) { ProblemPin foundedPin = null; if (!cache.TryGetValue(id, out foundedPin)) { foundedPin = await moderatePinContext.ModerateProblemPins.Include(problemPin => problemPin.Images).FirstOrDefaultAsync(pins => pins.Id == id); if (foundedPin != null) { cache.Set(foundedPin.Id, foundedPin, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(5))); } } return(foundedPin); }
public async Task <ResponseDTO> EditPublicPin(Guid oldDataId, ProblemPin newProblemPin) { var foundedPin = await publicPinContext.ProblemPins.Include(problemPin => problemPin.Images).FirstOrDefaultAsync(pins => pins.Id == oldDataId); publicPinContext.Entry(foundedPin).CurrentValues.SetValues(newProblemPin); int count = await publicPinContext.SaveChangesAsync(); if (count > 0) { cache.Set(foundedPin.Id, foundedPin, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(5))); } return(new ResponseDTO() { Message = "Пин успешно изменён", Status = true }); }
public async Task <IActionResult> EditModerationPin(Guid Id, [FromBody] EditProblemPinDTO moderateProblemPinDTO) { try { if (!ModelState.IsValid) { return(BadRequest()); } ProblemPin moderateProblemPin = await moderationPinService.GetModerationPinById(Id); if (moderateProblemPin == null) { logger.LogInformation($"GetModerationPinById dont found Id: {Id}"); return(NotFound(new ResponseDTO() { Message = "Пин не найден", Status = false })); } ResponseDTO answer = await moderationPinService.EditModerationPin(moderateProblemPin, moderateProblemPinDTO); logger.LogInformation($"Модератор: {moderateProblemPinDTO.ModeratorLogin} : {moderateProblemPinDTO.ModeratorId}, проверил и подтвердил пин: {moderateProblemPin.Id}"); return(Ok(answer)); } catch (ObjectNotFoundException ex) { logger.LogError(ex.Message); return(StatusCode(404, new ResponseDTO() { Message = "Пин не найден", Status = false })); } catch (Exception ex) { logger.LogError(ex.Message); return(StatusCode(500, new ResponseDTO() { Message = "На данный момент на стороне сервера ошибка сообщите администратору", Status = false })); } }
public async Task <IActionResult> GetModerationPinById(Guid id) { try { ProblemPin moderateProblemPin = await moderationPinService.GetModerationPinById(id); if (moderateProblemPin == null) { logger.LogInformation($"GetModerationPinById dont found Id: {id}"); return(NotFound(new ResponseDTO() { Message = "Пин не найден", Status = false })); } ResponseDTO answer = new ResponseDTO() { Status = true }; return(Ok(new { moderateProblemPin, answer })); } catch (ObjectNotFoundException ex) { logger.LogError(ex.Message); return(StatusCode(404, new ResponseDTO() { Message = "Пин не найден", Status = false })); } catch (Exception ex) { logger.LogError(ex.Message); return(StatusCode(500, new ResponseDTO() { Message = "На данный момент на стороне сервера ошибка сообщите администратору", Status = false })); } }
public async Task <ResponseDTO> DeleteModerationPin(ProblemPin foundedPin) { if (foundedPin.Images != null) { foreach (ImageCustom image in foundedPin.Images) { File.Delete(environment.WebRootPath + image.ImagePath); } } ProblemPin bufferPin = foundedPin; if (cache.TryGetValue(foundedPin.Id, out bufferPin)) { cache.Remove(foundedPin.Id); } moderatePinContext.ModerateProblemPins.Remove(foundedPin); await moderatePinContext.SaveChangesAsync(); return(new ResponseDTO() { Message = "Пин удалён", Status = true });; }
public async Task <ResponseDTO> SolvedProblemPinAccept(SolvedPinDTO solvedPinDTO) { //Remove from Moderation database table ProblemPin foundedPin = await publicPinContext.ProblemPins.Include(problemPin => problemPin.Images).FirstOrDefaultAsync(pins => pins.Id == solvedPinDTO.Id); publicPinContext.ProblemPins.Remove(foundedPin); // Add to Solved pins DataBase if (solvedPinDTO.Files.Count > 0) { SolvedPin solvedPin = new SolvedPin() { Id = foundedPin.Id, UserKeyId = foundedPin.UserKeyId, Name = foundedPin.Name, ProblemDescription = foundedPin.ProblemDescription, CreationDate = foundedPin.CreationDate, Images = foundedPin.Images, Lat = foundedPin.Lat, Lng = foundedPin.Lng, Report = solvedPinDTO.Report, Team = solvedPinDTO.Team, ModeratorId = foundedPin.ModeratorId, SolvedModerator = solvedPinDTO.ModeratorId }; List <SolvedImages> uploadedImages = new List <SolvedImages>(); foreach (var file in solvedPinDTO.Files) { FileInfo fileInfo = new FileInfo(file.FileName); string fileName = Guid.NewGuid().ToString() + fileInfo.Extension; if (!Directory.Exists(environment.WebRootPath + "\\PinPublicImages\\" + $"\\{solvedPin.Id}\\")) { Directory.CreateDirectory(environment.WebRootPath + "\\PinPublicImages\\" + $"\\{solvedPin.Id}\\"); } FileStream filestream = File.Create(environment.WebRootPath + "\\PinPublicImages\\" + $"\\{solvedPin.Id}\\" + fileName); await file.CopyToAsync(filestream); await filestream.FlushAsync(); SolvedImages image = new SolvedImages { Alt = fileName, ImagePath = $"\\PinPublicImages\\{solvedPin.Id}\\{fileName}", WebImagePath = "http://localhost:54968/PinPublicImages/" + solvedPin.Id + "/" + fileName, SolvedPin = solvedPin, solvedPinId = solvedPin.Id }; uploadedImages.Add(image); } solvedPin.SolvedImages = uploadedImages; await publicPinContext.SolvedPins.AddAsync(solvedPin); int count = await publicPinContext.SaveChangesAsync(); if (count > 0) { cache.Set(solvedPin.Id, solvedPin, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(5))); } return(new ResponseDTO() { Message = "Решение пина успешно подтверждено, пин добавлен в базу решённых пинов", Status = true }); } else { return(new ResponseDTO() { Message = "Ошибка с загрузкой фотографий", Status = false });; } }
public async Task <ResponseDTO> AddPublicPin(ProblemPinDTO problemPinDTO, Guid userId) { List <ProblemImages> uploadedImages = new List <ProblemImages>(); if (problemPinDTO.Files.Count > 0) { // Add to GModeration database table => transfer to moderation team ProblemPin problemPin = new ProblemPin { Lat = problemPinDTO.Lat, Lng = problemPinDTO.Lng, Name = problemPinDTO.Name, ProblemDescription = problemPinDTO.ProblemDescription, Address = problemPinDTO.Address, UserKeyId = userId }; foreach (var file in problemPinDTO.Files) { FileInfo fileInfo = new FileInfo(file.FileName); string fileName = Guid.NewGuid().ToString() + fileInfo.Extension; if (!Directory.Exists(environment.WebRootPath + "\\PinPublicImages\\" + $"\\{userId}\\")) { Directory.CreateDirectory(environment.WebRootPath + "\\PinPublicImages\\" + $"\\{userId}\\"); } FileStream filestream = File.Create(environment.WebRootPath + "\\PinPublicImages\\" + $"\\{userId}\\" + fileName); await file.CopyToAsync(filestream); await filestream.FlushAsync(); ProblemImages image = new ProblemImages { Alt = fileName, ImagePath = $"\\PinPublicImages\\{userId}\\{fileName}", WebImagePath = "http://localhost:54968/PinPublicImages/" + userId + "/" + fileName, problemPin = problemPin, problemPinId = problemPin.Id }; uploadedImages.Add(image); } problemPin.Images = uploadedImages; await moderatePinContext.ModerateProblemPins.AddAsync(problemPin); int count = await moderatePinContext.SaveChangesAsync(); if (count > 0) { cache.Set(problemPin.Id, problemPin, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(5))); } return(new ResponseDTO() { Message = "Пин успешно добавлен и на данный момент проходит модерацию", Status = true });; } else { return(new ResponseDTO() { Message = "Ошибка с загрузкой фотографий", Status = false });; } }