public async Task <IActionResult> Post([FromBody] DatabaseConnection databaseConnection) { if (ModelState.IsValid) { databaseConnection.Id = DataUtil.GenerateUniqueId(); _logger.Info("Creating database: {@databaseConnection}", databaseConnection); await _databaseRepository.AddAsync(databaseConnection); return(Ok(databaseConnection)); } _logger.Info("Creating database isn't correct format. Errors: {@error}", ModelState.Values.SelectMany(a => a.Errors)); return(BadRequest()); }
public async Task <ProjectDto> AddProject(SaveProjectDto projectDto) { TinyMapper.Bind <SaveProjectDto, Project>(); TinyMapper.Bind <Project, ProjectDto>(); var project = TinyMapper.Map <Project>(projectDto); project.Created = UnixTimeStamp(); await _projectRepository.AddAsync(project); await _projectRepository.CommitAsync(); return(TinyMapper.Map <ProjectDto>(project)); }
public async Task <IActionResult> Add(FilmViewModel model, IFormFile uploadedFile) { if (uploadedFile != null) { if (!IsCorrectFormat(Path.GetExtension(uploadedFile.FileName))) { ModelState.AddModelError(nameof(model.PosterPath), "Недопустимый формат данных!"); } if (!IsCorrectFileLength(uploadedFile.Length)) { ModelState.AddModelError(nameof(model.PosterPath), "Размер превышает норму!"); } } if (!ModelState.IsValid) { return(View(model)); } var data = _mapper.Map <Film>(model); data.UserId = _userManager.GetUserId(User); if (uploadedFile != null) { string path = GetFilePath(uploadedFile.FileName); using var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create); await uploadedFile.CopyToAsync(fileStream); data.PosterPath = path; } await _filmRepository.AddAsync(data); _logger.LogDebug("Add film: ", @model); return(RedirectToAction("Index", "Catalog")); }
static void Main(string[] args) { bool closeApp = false; while (!closeApp) { Console.WriteLine("1. GetAllGames"); Console.WriteLine("2. Get All Games using sql query for Ubisoft"); Console.WriteLine("3. Get Games using Pagniation"); Console.WriteLine("4. Insert Game"); Console.WriteLine("5. Delete Game"); Console.WriteLine("6. Search Game by Name"); Console.WriteLine("7. Sort by Games"); Console.WriteLine("8. Exit"); Console.WriteLine(); Console.Write("Enter your choice: "); string option = Console.ReadLine().Replace(" ", ""); var result = Enumerable.Empty <Games>().AsQueryable(); PaginatedResponse <Games> response = null; switch (option) { case "1": result = gamesDBRepository.GetAllAsync(null).GetAwaiter().GetResult(); if (result.Any()) { PrintData(result.AsQueryable()); } break; case "2": string query = "Select * from c WHERE c.name = 'Ubisoft'"; result = gamesDBRepository.GetAllAsync(query, null, int.MaxValue, "Ubisoft").GetAwaiter().GetResult().AsQueryable(); PrintData(result.AsQueryable()); break; case "3": Console.WriteLine("Pass Limit"); int limit = 0; int.TryParse(Console.ReadLine().Replace(" ", ""), out limit); Console.WriteLine("Pass continuation token if any"); string token = Console.ReadLine().Replace(" ", ""); response = gamesDBRepository.GetManyWithPaginationAsync(string.IsNullOrWhiteSpace(token) ? null : token, limit, null, null, null, null).GetAwaiter().GetResult(); Console.WriteLine("Continuation token " + response.ContinuationToken ?? "is Empty"); PrintPagniatedData(response.ResultSet.ToList()); break; case "4": Games game = GetGameData(); gamesDBRepository.AddAsync(game, game.Name).GetAwaiter().GetResult(); Console.WriteLine("Game Created Successfully"); break; case "5": Console.WriteLine("Enter Game Id to Delete : "); string id = Console.ReadLine(); Console.WriteLine("Enter its partitionKey : "); string partionKey = Console.ReadLine(); gamesDBRepository.DeleteAsync(id, partionKey).GetAwaiter().GetResult(); Console.WriteLine("Game Deleted Successfully"); break; case "6": Console.WriteLine("Enter any string to search"); string searchTerm = Console.ReadLine(); Expression <Func <Games, bool> > searchFilter = null; searchFilter = (x => x.Name.ToLower().Contains(searchTerm.ToLower()) || x.Location.ToLower().Contains(searchTerm.ToLower()) || x.VedioGames.Any(y => y.Name.ToLower().Contains(searchTerm.ToLower())) ); result = gamesDBRepository.GetAllAsync(searchFilter).GetAwaiter().GetResult(); PrintData(result); break; case "7": Console.WriteLine("Enter which column Name you want to sort"); string sortColumn = Console.ReadLine(); Console.WriteLine("Enter sort order + for Asc and - for Desc"); string sortOrder = Console.ReadLine(); response = gamesDBRepository.GetManyWithPaginationAsync(null, int.MaxValue, null, sortColumn, getSortOrder(sortOrder)) .GetAwaiter().GetResult(); PrintPagniatedData(response.ResultSet.ToList()); break; case "8": gamesDBRepository.Dispose(); closeApp = true; break; default: Console.WriteLine("Invalid Option Selected"); break; } Console.WriteLine("Press any key continue !!!"); Console.ReadKey(); Console.Clear(); } }