public async Task <bool> Put(long id, JObject json)
        {
            try
            {
                _invillaContext = new InvillaContext();

                var model = JsonConvert.DeserializeObject <LoanViewModel>(json.ToString());

                if (model.LoanDateEnd == null)
                {
                    return(false);
                }

                var loanDB = _invillaContext.Loans.Select(x => x).Where(x => x.Id == id).FirstOrDefault();
                loanDB.LoanDateEnd = model.LoanDateEnd;
                var gameDB = _invillaContext.Games.Select(x => x).Where(x => x.Id == loanDB.IdGames).FirstOrDefault();
                gameDB.Loaned = false;
                _invillaContext.Update(gameDB);
                _invillaContext.Update(loanDB);
                _invillaContext.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemple #2
0
        public async Task <bool> Put(long id, JObject json)
        {
            try
            {
                var model = JsonConvert.DeserializeObject <RoleViewModel>(json.ToString());

                using (_invillaContext = new InvillaContext()) {
                    if (model.Id == null)
                    {
                        return(false);
                    }

                    var roleDB = _invillaContext.Roles.Select(x => x).Where(x => x.Id == id).FirstOrDefault();

                    roleDB.Role             = model.Role;
                    roleDB.RegistrationDate = DateTime.Now;

                    _invillaContext.Update(roleDB);
                    _invillaContext.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemple #3
0
        public async Task <bool> Put(long id, JObject json)
        {
            try
            {
                var model = JsonConvert.DeserializeObject <FriendsViewModel>(json.ToString());

                using (_invillaContext = new InvillaContext()) {
                    if (model.Id == null)
                    {
                        return(false);
                    }

                    var friendDB = _invillaContext.Friends.Select(x => x).Where(x => x.Id == id).FirstOrDefault();

                    friendDB.FullName = model.FullName;

                    _invillaContext.Update(friendDB);
                    _invillaContext.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public async Task <bool> Delete(long id)
        {
            try
            {
                _invillaContext = new InvillaContext();

                if (id == null)
                {
                    return(false);
                }

                var loanDB = _invillaContext.Loans.Select(x => x).Where(x => x.Id == id).FirstOrDefault();
                var gameDB = _invillaContext.Games.Select(x => x).Where(x => x.Id == loanDB.IdGames).FirstOrDefault();
                gameDB.Loaned = false;
                _invillaContext.Remove(loanDB);
                _invillaContext.Update(gameDB);
                _invillaContext.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public async Task <bool> Renew(long id)
        {
            try
            {
                _invillaContext = new InvillaContext();

                if (id == null)
                {
                    return(false);
                }
                var loanDB = _invillaContext.Loans.Select(x => x).Where(x => x.Id == id).FirstOrDefault();
                loanDB.LoanDateBegin = DateTime.Now;
                _invillaContext.Update(loanDB);
                _invillaContext.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemple #6
0
        public async Task <bool> GetLoginByName(JObject json)
        {
            try
            {
                _invillaContext = new InvillaContext();
                var model   = JsonConvert.DeserializeObject <LoginViewModel>(json.ToString());
                var loginDB = _invillaContext.Logins.Where(x => x.FullName == model.FullName).FirstOrDefault();
                var roleDB  = _invillaContext.Roles.Where(x => x.Id == model.IdRole).FirstOrDefault();

                var role = (string.IsNullOrEmpty(roleDB.Role)) ? "admin" : roleDB.Role;

                model.Password = CryptoConfig.EncryptPassword(model.Password);

                if (model.FullName == loginDB.FullName && model.Password == loginDB.Password)
                {
                    var claims = new List <Claim>()
                    {
                        new Claim("UserLoan", model.FullName),
                        new Claim("Password", model.Password),
                        new Claim("Role", role)
                    };

                    var token = JwtTokenUtils.GenerateInvillaUserToken(claims);
                    loginDB.Token = token;
                    _invillaContext.Update(loginDB);
                    _invillaContext.SaveChanges();

                    return(true);
                }

                return(false);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        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);
            }
        }