Example #1
0
        public async Task <IActionResult> PutAlbum(Guid id, Album album)
        {
            if (id != album.Id)
            {
                return(BadRequest());
            }

            _context.Entry(album).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AlbumExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #2
0
        public async Task <IActionResult> PutAfetado(int id, Afetado afetado)
        {
            if (id != afetado.AfetadoId)
            {
                return(BadRequest());
            }

            _context.Entry(afetado).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AfetadoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #3
0
        public async Task <IActionResult> PutMedia(Guid id, MediaItem media)
        {
            if (id != media.Id)
            {
                return(BadRequest());
            }

            _context.Entry(media).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MediaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #4
0
        public async Task <IActionResult> PutFriendship(int id, Friendship friendship)
        {
            if (id != friendship.Id)
            {
                return(BadRequest());
            }

            _context.Entry(friendship).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FriendshipExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutEmployee([FromRoute] long id, [FromBody] Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employee.employeeId)
            {
                return(BadRequest());
            }

            _context.Entry(employee).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutBrewery([FromRoute] int id, [FromBody] Brewery brewery)
        {
            if (id != brewery.BreweryId)
            {
                return(BadRequest());
            }

            _context.Entry(brewery).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_context.Brewery.Any(e => e.BreweryId == id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #7
0
        public async Task <IActionResult> PutSensor(int id, Sensor sensor)
        {
            if (id != sensor.SensorId)
            {
                return(BadRequest());
            }

            _context.Entry(sensor).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SensorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #8
0
        public async Task <IActionResult> PutPaises(int id, Paises paises)
        {
            if (id != paises.Id)
            {
                return(BadRequest());
            }

            _context.Entry(paises).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PaisesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #9
0
        public async Task <IActionResult> PutIncidente(int id, Incidente incidente)
        {
            if (id != incidente.IncidenteId)
            {
                return(BadRequest());
            }

            _context.Entry(incidente).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!IncidenteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #10
0
        public async Task <IActionResult> Create([Bind("Order,CategoryId,BrandId,ImageUrl,Price,ProductionDate,Manufacturer,Name,Id")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BrandId"]    = new SelectList(_context.Brands, "Id", "Id", product.BrandId);
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Id", product.CategoryId);
            return(View(product));
        }
        public async Task <ActionResult <T> > Delete(long id)
        {
            var entity = await _table.FindAsync(id);

            if (entity == null)
            {
                return(NotFound());
            }

            _table.Remove(entity);
            await _context.SaveChangesAsync(new System.Threading.CancellationToken());

            return(Ok(entity));
        }
Example #12
0
        public virtual async Task <T> InsertAsync(T item)
        {
            DbSet.Add(item);
            await Context.SaveChangesAsync();

            return(item);
        }
Example #13
0
        public async Task <GameSummaryViewModel> Handle(CreateGameCommand request)
        {
            if (_context.Games.Any(x => x.Name == request.GameConfig.GameName))
            {
                throw new ValidationException(new[] { new ValidationFailure("Name", $"A game named \"{request.GameConfig.GameName}\" already exist.  Please choose a different name.") });
            }
            var output = new Game
            {
                GameGuid        = Guid.NewGuid(),
                Name            = request.GameConfig.GameName,
                Rules           = request.GameConfig.Rules,
                ProgressionMode = (int)request.GameConfig.ProgressionMode,
                Description     = request.GameConfig.Description,
                GameType        = (int)request.GameConfig.GameType,
                HostId          = request.HostId,
                Status          = (int)GameStatus.WaitingForPlayers
            };

            output.Actions.Add(new GameAction {
                UserId      = request.HostId,
                Action      = (int)Actions.Created,
                DateTime    = DateTime.Now,
                ActionValue = $"Created game with the name \"{request.GameConfig.GameName}\""
            });
            _context.Games.Add(output);
            await _context.SaveChangesAsync();

            var gameList = _context.Games.AsNoTracking().Where(x => x.GameId == output.GameId);

            return(gameList.ProjectTo <GameSummaryViewModel>().Single());
        }
Example #14
0
        public async Task <GameActionViewModel[]> Handle(HostChosePlayerCommand request)
        {
            var game = _context.Games
                       .Include(x => x.Players.Select(p => p.User))
                       .FirstOrDefault(x => x.GameId == request.GameId);

            if (game.HostId != request.UserId)
            {
                throw new ValidationException(new[] { new ValidationFailure("HostId", $"User with Id of \"{request.UserId}\" is not the host.") });
            }

            // chose player game
            var nextPlayer     = game.Players.Single(x => x.UserId == request.NextPlayerId);
            var gameActionList = new List <GameAction>();

            game.CurrentGamePlayerId = nextPlayer.GamePlayerId;
            var gameAction = new GameAction
            {
                GameId      = request.GameId,
                UserId      = request.UserId,
                DateTime    = DateTime.Now,
                Action      = (int)Actions.StatusChanged,
                ActionValue = $"has selected the next player \"{nextPlayer.User.DisplayName}\"."
            };

            _context.GameActions.Add(gameAction);
            game.Status = (int)GameStatus.WaitingForPlayer;
            gameActionList.Add(gameAction);
            await _context.SaveChangesAsync();

            return(GameHelpers.ProcessNextPlayerResults(gameActionList, nextPlayer, gameAction, _context));
        }
        public async Task <ViewModels.User.UserViewModel> Handle(CreateUserCommand request)
        {
            // TODO: lame validation, make it better
            var existAlready = _context.Users.Any(x => x.DisplayName == request.UserConfig.DisplayName || x.Email == request.UserConfig.Email);

            if (existAlready)
            {
                throw new ArgumentException("Display name or username already exist or something else bad happened.");
            }

            // create user in shanespace.auth
            var userCreateRequest = await _userWebProxy.RegisterAsync(ConfigurationManager.AppSettings["ShaneSpaceAuthSiteKey"], new RegisterUser
            {
                Email    = request.UserConfig.Email,
                Password = request.UserConfig.Password
            });

            // create user in shanespace.gamesite
            var output = new User
            {
                AuthId      = userCreateRequest.Id,
                DisplayName = request.UserConfig.DisplayName,
                Email       = request.UserConfig.Email
            };

            _context.Users.Add(output);
            await _context.SaveChangesAsync();

            return(_context.Users
                   .AsNoTracking()
                   .Where(x => x.Id == output.Id)
                   .ProjectTo <ViewModels.User.UserViewModel>()
                   .Single());
        }
Example #16
0
        public async Task <GameActionViewModel[]> Handle(StartGameCommand request)
        {
            var game = _context.Games
                       .Include(x => x.Players.Select(p => p.User))
                       .FirstOrDefault(x => x.GameId == request.GameId);

            if (game.HostId != request.UserId)
            {
                throw new ValidationException(new[] { new ValidationFailure("HostId", $"User with Id of \"{request.UserId}\" is not the host.") });
            }

            // Start game
            var gameActionList = new List <GameAction>();
            var gameAction     = new GameAction
            {
                GameId      = request.GameId,
                UserId      = request.UserId,
                DateTime    = DateTime.Now,
                Action      = (int)Actions.StartedGame,
                ActionValue = "has started the game."
            };

            _context.GameActions.Add(gameAction);
            gameActionList.Add(gameAction);

            // set next player
            GamePlayer nextPlayer;
            GameAction nextPlayerAction;

            GameHelpers.GetNexPlayer(request, game, gameActionList, out nextPlayer, out nextPlayerAction, _context);
            await _context.SaveChangesAsync();

            return(GameHelpers.ProcessNextPlayerResults(gameActionList, nextPlayer, nextPlayerAction, _context));
        }
Example #17
0
        public async Task <TMdl> ExecuteAsync(TMdl entity)
        {
            await _dbset.AddAsync(entity);

            await _context.SaveChangesAsync();

            return(entity);
        }
Example #18
0
        public async Task <IActionResult> Student()
        {
            db.teacher.Add(new Teacher()
            {
                name = "pgb"
            });
            await db.SaveChangesAsync();

            return(Content(""));
        }
        public async Task <FeedbackViewModel> Handle(AddFeedbackCommand message)
        {
            var newFeedback = new Models.Feedback
            {
                UserId       = message.UserId,
                FeedbackType = (int)message.FeedbackBody.FeedbackType,
                FeedbackText = message.FeedbackBody.FeedbackText
            };

            _context.Feedback.Add(newFeedback);
            await _context.SaveChangesAsync();

            return(_context.Feedback.Where(x => x.FeedbackId == newFeedback.FeedbackId).ProjectTo <FeedbackViewModel>().Single());
        }
Example #20
0
 public UserRepository(CoreContext context)
 {
     _context = context;
     if (!_context.Users.Any())
     {
         _context.Users.AddAsync(new User
                                 (
                                     "admin",
                                     "admin",
                                     "Qwerty1234!",
                                     "Admin",
                                     "Admin"
                                 ));
     }
     _context.SaveChangesAsync();
 }
Example #21
0
        public async Task SaveCustomer(EditCustomer customer)
        {
            using (var db = new CoreContext())
            {
                var dbCustomer = await db.Customers.FirstAsync(x => x.Id == customer.Id);

                // AutoMapper
                dbCustomer.City        = customer.City;
                dbCustomer.CompanyName = customer.CompanyName;
                dbCustomer.FirstName   = customer.FirstName;
                dbCustomer.PostalCode  = customer.PostalCode;
                dbCustomer.Street      = customer.Street;

                // 2 SQL Statements
                //UPDATE abhängig aus der Änderung zwischen Datenbankwerten (!) <--> customer
                await db.SaveChangesAsync();
            }
        }
        public async Task <GameActionViewModel> Handle(JoinGameCommand request)
        {
            _context.GamePlayers.Add(new GamePlayer {
                UserId = request.UserId, GameId = request.GameId
            });
            var gameAction = new GameAction
            {
                GameId      = request.GameId,
                UserId      = request.UserId,
                DateTime    = DateTime.Now,
                Action      = (int)Actions.Joined,
                ActionValue = "has joined the game."
            };

            _context.GameActions.Add(gameAction);
            await _context.SaveChangesAsync();

            return(_context.GameActions.Where(x => x.GameActionId == gameAction.GameActionId).ProjectTo <GameActionViewModel>().Single());
        }
Example #23
0
        public async Task <MessageViewModel> Handle(CreateGameMessageCommand request)
        {
            var game    = _context.Games.Single(x => x.GameId == request.GameId);
            var message = new Message
            {
                ComposeDate     = DateTime.Now,
                GameId          = request.GameId,
                ComposerId      = request.ComposerId,
                MessageContents = request.MessageContents
            };

            game.Messages.Add(message);
            await _context.SaveChangesAsync();

            var newMessage = _context.Messages.Where(x => x.MessageId == message.MessageId)
                             .ProjectTo <MessageViewModel>().Single();

            return(newMessage);
        }
Example #24
0
    public async Task <IActionResult> Send([FromBody] EmailSurveyToClient emailSurveyToClient)
    {
        var clientTask = _context.Clients.Where(e => e.Email == emailSurveyToClient.Email).FirstOrDefaultAsync();
        var surveyTask = _context.Surveys.Where(e => e.Id == emailSurveyToClient.SurveyId).FirstOrDefaultAsync();
        await Task.WhenAll(clientTask, surveyTask);

        var client = await clientTask;
        var survey = await surveyTask;

        var clientSurvey = new ClientSurveys
        {
            Client          = client,
            Survey          = survey,
            ClientSurveyKey = Guid.NewGuid()
        };

        await _context.ClientSurveys.AddAsync(clientSurvey);

        await _context.SaveChangesAsync();

        try
        {
            var email = new MailMessage(
                from: "*****@*****.**",
                to: clientSurvey.Client.Email,
                subject: "New Questionnaire!",
                body: $"Hello {clientSurvey.Client.FirstName} {clientSurvey.Client.LastName}, please complete the following survey: <a href='https://localhost:44331/{clientSurvey.Client.Email}/{clientSurvey.ClientSurveyKey}' target='_blank'>{clientSurvey.Survey.Title}</a>"
                )
            {
                IsBodyHtml = true
            };
            // TODO: add environment var for email
            await _smtp.SendMailAsync(email);
        }
        catch (Exception)
        {
            throw;
        }


        return(Ok());
    }
Example #25
0
        public async Task <GameActionViewModel> Handle(LeaveGameCommand request)
        {
            var game       = _context.Games.Include(x => x.Players).Single(x => x.GameId == request.GameId);
            var gamePlayer = game.Players.Single(x => x.GameId == request.GameId && x.UserId == request.UserId);

            _context.GamePlayers.Remove(gamePlayer);
            var leaveGameAction = new GameAction
            {
                GameId      = request.GameId,
                UserId      = request.UserId,
                DateTime    = DateTime.Now,
                Action      = (int)Actions.Exited,
                ActionValue = "has left the game."
            };

            _context.GameActions.Add(leaveGameAction);
            await _context.SaveChangesAsync();

            return(_context.GameActions.Where(x => x.GameActionId == leaveGameAction.GameActionId).ProjectTo <GameActionViewModel>().Single());
        }
Example #26
0
        public async Task <GameActionViewModel[]> Handle(PlayerRolledDieCommand request)
        {
            var game = _context.Games
                       .Include(x => x.Players.Select(p => p.User))
                       .FirstOrDefault(x => x.GameId == request.GameId);

            // wait 5 seconds so you can see a nice spinning animation in UI...
            await Task.Delay(5000);

            // calculate roll
            List <Die> dieList  = request.Die.ToObject <List <Die> >();
            var        dieCount = dieList.Count;

            foreach (var die in dieList)
            {
                die.DieValue = _random.Next(1, die.DieSideCount);
            }
            // build game action
            var gameActionList = new List <GameAction>();
            var gameAction     = new GameAction
            {
                GameId      = request.GameId,
                UserId      = request.UserId,
                DateTime    = DateTime.Now,
                Action      = (int)Actions.Moved,
                ActionValue = $"has rolled {dieCount} die and got the following values: {string.Join(", ", dieList.Select(x => $"D{x.DieSideCount}:{x.DieValue}"))}"
            };

            _context.GameActions.Add(gameAction);
            gameActionList.Add(gameAction);

            // set next player
            GamePlayer nextPlayer;
            GameAction nextPlayerAction;

            GameHelpers.GetNexPlayer(request, game, gameActionList, out nextPlayer, out nextPlayerAction, _context);

            await _context.SaveChangesAsync();

            return(GameHelpers.ProcessNextPlayerResults(gameActionList, nextPlayer, nextPlayerAction, _context));
        }
        public async Task <GameActionViewModel> Handle(AutoStatusChangeCommand request)
        {
            var game = _context.Games.Single(x => x.GameId == request.GameId);

            game.Status = (int)GameStatus.WaitingForPlayers;
            var leaveGameAction = new GameAction
            {
                UserId      = Constants.SystemUser,
                DateTime    = DateTime.Now,
                Action      = (int)Actions.StatusChanged,
                ActionValue = "has automatically changed the game status to \"Waiting For Players\" because too many players have left the game."
            };

            game.Actions.Add(leaveGameAction);
            await _context.SaveChangesAsync();

            var viewModel = _context.GameActions.Where(x => x.GameActionId == leaveGameAction.GameActionId).ProjectTo <GameActionViewModel>().Single();

            viewModel.AdditionalInfo = new { Status = GameStatus.WaitingForPlayers };
            return(viewModel);
        }
Example #28
0
        public async Task SaveCustomer(EditCustomerEntry originalCustomer, EditCustomer customer)
        {
            using (var db = new CoreContext())
            {
                var dbCustomer = new Customers();
                dbCustomer.Id          = originalCustomer.Id;
                dbCustomer.City        = originalCustomer.City;
                dbCustomer.CompanyName = originalCustomer.CompanyName;
                dbCustomer.FirstName   = originalCustomer.FirstName;
                dbCustomer.PostalCode  = originalCustomer.PostalCode;
                dbCustomer.Street      = originalCustomer.Street;
                db.Customers.Attach(dbCustomer);

                dbCustomer.City        = customer.City;
                dbCustomer.CompanyName = customer.CompanyName;
                dbCustomer.FirstName   = customer.FirstName;
                dbCustomer.PostalCode  = customer.PostalCode;
                dbCustomer.Street      = customer.Street;

                // NUR 1 SQL Statement!
                // UPDATE abhängig aus der Änderung zwischen orignalCustomer <--> customer
                await db.SaveChangesAsync();
            }
        }
Example #29
0
 public async Task Create(Student std)
 {
     _context.Students.Add(std);
     await _context.SaveChangesAsync();
 }
Example #30
0
 public async Task <bool> Commit()
 {
     return(await _context.SaveChangesAsync() > 0);
 }