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); } }
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 <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 { }); } }
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); } }
/// <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 { }); } }
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); } }
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 { }); } }
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); } }
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); } }
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> 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); } }
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); } }