public async Task <IActionResult> AddTable(AddTableViewModel tableViewModel) { var user = await _userManager.FindByIdAsync(HttpContext.User.GetUserId()); //ApplicationUser applicationUser = await _context.ApplicationUsers.FirstOrDefaultAsync(w => w.Id == user.Id); //Restaurant restaurantData = await _context.Restaurants.FirstOrDefaultAsync(w => w.ApplicationUser.Id == user.Id); if (user.AccountType == "Restaurant") { Restaurant restaurant = _applicationService.GetRestaurantByUserId(user.Id); if (ModelState.IsValid) { RestaurantTable table = new RestaurantTable() { RestaurantTableSeats = tableViewModel.TableSeats }; //_context.RestaurantTables.Add(table); _applicationService.AddTableByRestaurantId(table, restaurant.Id); if (restaurant == null) { user.RestaurantData = new Restaurant(); } if (restaurant.RestaurantTables == null) { user.RestaurantData.RestaurantTables = new List <RestaurantTable>(); } restaurant.RestaurantTables.Add(table); //_context.SaveChanges(); return(RedirectToAction("Index")); } } return(View(tableViewModel)); }
public async Task <IActionResult> AddTable(AddTableViewModel tableViewModel) { var user = await _userManager.FindByIdAsync(HttpContext.User.GetUserId()); if (ModelState.IsValid) { bool success = _applicationService.AddTablesByUserId(tableViewModel.TableSeats, tableViewModel.TableCount, user.Id); /*for (int i = 0; i < tableViewModel.TableCount; i++) * { * RestaurantTable table = new RestaurantTable() * { * RestaurantTableSeats = tableViewModel.TableSeats * }; * _applicationService.AddTableByRestaurantId(table, restaurant.Id); * }*/ if (success) { TempData["Success"] = "Sėkmingai įdėjote " + tableViewModel.TableCount.ToString() + " staliukus!"; } return(RedirectToAction("ViewTables")); } return(View(tableViewModel)); }
public async Task <IActionResult> EditTable(AddTableViewModel tableViewModel) { try { await this.tableService.EditTableAsync(tableViewModel); } catch (Exception ex) { return(this.BadRequest(ex.Message)); } return(this.RedirectToAction("Tables")); }
public async Task EditTableAsync(AddTableViewModel tableViewModel) { if (this.tableRepository.All().Any(x => x.Number == tableViewModel.Number)) { throw new InvalidOperationException("The table number already exists!"); } var table = this.tableRepository.All().FirstOrDefault(x => x.Id == tableViewModel.Id); table.Number = tableViewModel.Number; table.Capacity = tableViewModel.Capacity; table.Code = this.RandomString(6); await this.tableRepository.SaveChangesAsync(); }
public async Task AddTableAsync(AddTableViewModel tableViewModel) { var mapper = AutoMapperConfig.MapperInstance; if (this.tableRepository.All().Any(x => x.Number == tableViewModel.Number)) { throw new InvalidOperationException("The table number already exists!"); } var table = mapper.Map <AddTableViewModel, Table>(tableViewModel); table.Code = this.RandomString(6); await this.tableRepository.AddAsync(table); await this.tableRepository.SaveChangesAsync(); }
public async Task <Store> AddTablesAsync(int amount) { var client = getHttpClient(); var tablesViewModel = new AddTableViewModel { TablesAmount = amount }; var tablesSerialized = _serializerService.Serialize(tablesViewModel); var httpContent = new StringContent(tablesSerialized, Encoding.UTF8, "application/json"); var result = await client.PostAsync(_baseUrl, httpContent); var storeSerialized = await result.Content.ReadAsStringAsync(); var store = _serializerService.Deserialize <Store>(storeSerialized); return(store); }
internal void AddTable(AddTableViewModel addTableViewModel) { string tableId = Guid.NewGuid().ToString(); var sdTable = new SDDataTable( tableId, addTableViewModel.Name, true, addTableViewModel.ColumnViewModels.Select(c => new SDColumn(Guid.NewGuid().ToString(), c.Name, c.DataType, true, tableId)).ToList() ); _dbTableRepository.Add(sdTable); _efContext.SDDataTables.Add(sdTable); _efContext.SaveChanges(); var table = _dbTableRepository.List(sdTable); _view.AddGrid(table); }
public async Task AddTableAsyncWorksCorrectly() { var addTable = new AddTableViewModel() { Id = 15, Number = 5, Capacity = 6, }; await this.TableService.AddTableAsync(addTable); var actual = this.DbContext.Tables.FirstOrDefault(x => x.Id == 15); Assert.Equal(15, actual.Id); Assert.Equal(5, actual.Number); Assert.Equal(6, actual.Capacity); }
public async Task EditTableAsyncWorksCorrectly() { await this.PopulateDB(); var editTable = new AddTableViewModel() { Id = 1, Capacity = 20, Number = 19, }; await this.TableService.EditTableAsync(editTable); var actual = this.DbContext.Tables.FirstOrDefault(x => x.Id == 1); Assert.Equal(editTable.Id, actual.Id); Assert.Equal(editTable.Capacity, actual.Capacity); Assert.Equal(editTable.Number, actual.Number); Assert.NotEqual("code1", actual.Code); }