示例#1
0
        public async Task <RoleViewModel> Post(JObject json)
        {
            _invillaContext = new InvillaContext();

            try
            {
                var model = JsonConvert.DeserializeObject <RoleViewModel>(json.ToString());
                model.RegistrationDate = DateTime.Now;
                var role = new RolesEntity
                {
                    Role             = model.Role,
                    RegistrationDate = model.RegistrationDate
                };
                _invillaContext.Add(role);
                _invillaContext.SaveChanges();

                return(model);
            }
            catch (Exception ex)
            {
                return(new RoleViewModel
                {
                });
            }
        }
示例#2
0
        public async Task <LoginViewModel> Post(JObject json)
        {
            _invillaContext = new InvillaContext();

            try
            {
                var model = JsonConvert.DeserializeObject <LoginViewModel>(json.ToString());
                model.RegistrationDate = DateTime.Now;
                model.Password         = CryptoConfig.EncryptPassword(model.Password);

                var Users = new LoginsEntity
                {
                    FullName         = model.FullName,
                    RegistrationDate = model.RegistrationDate,
                    Password         = model.Password,
                    IdRole           = 1
                };
                _invillaContext.Add(Users);
                _invillaContext.SaveChanges();

                return(model);
            }
            catch (Exception ex)
            {
                return(new LoginViewModel
                {
                });
            }
        }
示例#3
0
        /// <summary>
        /// Persiste os dados da requisição
        /// </summary>
        /// <param name="json">Json do Controller</param>
        /// <returns>Modelo WeatherForeCast</returns>
        public async Task <FriendsViewModel> Post(JObject json)
        {
            _invillaContext = new InvillaContext();

            try
            {
                var modelo = JsonConvert.DeserializeObject <FriendsViewModel>(json.ToString());
                modelo.RegistrationDate = DateTime.Now;
                var friends = new FriendsEntity
                {
                    Age              = modelo.Age,
                    FullName         = modelo.FullName,
                    RegistrationDate = modelo.RegistrationDate
                };
                _invillaContext.Add(friends);
                _invillaContext.SaveChanges();

                return(modelo);
            }
            catch (Exception ex)
            {
                return(new FriendsViewModel
                {
                });
            }
        }
示例#4
0
        public async Task <bool> Post(LoanViewModel model)
        {
            _invillaContext = new InvillaContext();

            try
            {
                foreach (var game in model.IdGame)
                {
                    if (await GetLoanGameById((long)game))
                    {
                        return(false);
                    }

                    var loans = new LoansEntity
                    {
                        IdFriend      = (long)model.IdFriend.FirstOrDefault(),
                        IdGames       = (long)game,
                        LoanDateBegin = (DateTime)model.LoanDateBegin
                    };

                    //Set Game Loaned
                    var gameDB = _invillaContext.Games.Select(x => x).Where(x => x.Id == game).FirstOrDefault();
                    gameDB.Loaned = true;

                    _invillaContext.Update(gameDB);
                    _invillaContext.Add(loans);
                    _invillaContext.SaveChanges();
                }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }