public async Task <IActionResult> CreateProblemPin([FromForm] ProblemPinDTO problemPinDTO) { try { if (!ModelState.IsValid) { return(BadRequest()); } ResponseDTO answer = await publicPinServiceCRUD.AddPublicPin(problemPinDTO, problemPinDTO.UserId); return(Ok(new { 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 <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 <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 });; } }