public async Task <ResponseDTO> AddModerator(Admin admin, ModeratorDTO addModeratorDTO) { string password = BCrypt.Net.BCrypt.HashPassword(addModeratorDTO.Password); Moderator moderator = new Moderator() { Login = addModeratorDTO.Login, Password = password, LastName = addModeratorDTO.LastName, FirstName = addModeratorDTO.FirstName, Role = Role.Moderator }; context.Moderators.Add(moderator); int savedCount = await context.SaveChangesAsync(); if (savedCount > 0) { Admin newAdmin = admin; newAdmin.AddedModerators += 1; context.Entry(admin).CurrentValues.SetValues(newAdmin); await context.SaveChangesAsync(); } return(new ResponseDTO() { Message = $"Вы успешно добавили {moderator.LastName} {moderator.FirstName} в роли модератора", Status = true, ResponseData = moderator }); }
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> AddAdmin(AdminDTO addAdminDTO) { string password = BCrypt.Net.BCrypt.HashPassword(addAdminDTO.Password); Admin admin = new Admin() { Login = addAdminDTO.Login, Password = password, LastName = addAdminDTO.LastName, FirstName = addAdminDTO.FirstName, Role = Role.Admin }; context.Admins.Add(admin); await context.SaveChangesAsync(); return(new ResponseDTO() { Message = $"Вы успешно добавили {admin.LastName} {admin.FirstName} в роли админа", Status = true, ResponseData = admin }); }
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 });; } }