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> Delete(long id)
        {
            try
            {
                _invillaContext = new InvillaContext();
                _serviceLoans   = new ServiceLoans();

                if (id == null || await _serviceLoans.GetLoanFriendById(id))
                {
                    return(false);
                }

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

                if (roleDB != null)
                {
                    return(false);
                }

                _invillaContext.Remove(loginDB);
                _invillaContext.SaveChanges();

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

                if (id == null || await _serviceLoans.GetLoanGameById(id))
                {
                    return(false);
                }

                var gameDB = _invillaContext.Games.Select(x => x).Where(x => x.Id == id).FirstOrDefault();
                _invillaContext.Remove(gameDB);
                _invillaContext.SaveChanges();

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

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

                if (loginDB != null)
                {
                    return(false);
                }

                _invillaContext.Remove(roleDB);
                _invillaContext.SaveChanges();

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