public ChargeLevel ReadFromDatabase(int level) { using (var ipPhoneEntities = new IPPhoneEntities()) { return(ipPhoneEntities.ChargeLevels.SingleOrDefault(c => c.Level == level)); } }
public List <ContactEntity> ReadAllFromDatabase() { using (var ipPhoneEntities = new IPPhoneEntities()) { var contactEntities = new List <ContactEntity>(); ipPhoneEntities.Contacts.ForEach(c => contactEntities.Add(ContactEntity.GetInstance(c))); return(contactEntities); } }
public void DeleteInDatabase(Guid id) { using (var ipPhoneEntities = new IPPhoneEntities()) { var contact = ipPhoneEntities.Contacts.SingleOrDefault(c => c.Id.Equals(id)); if (contact != null) { ipPhoneEntities.Contacts.Remove(contact); } ipPhoneEntities.SaveChanges(); } }
public void Validate(string token, ClaimsIdentity userLogin) { IPPhoneEntities ipphoneEntities = new IPPhoneEntities(); User user = ipphoneEntities.Users.Where(c => c.Name.Equals(userLogin.Name)).SingleOrDefault(); if (user == null) { userService.CreateUser(userLogin); } InsertUserToken(user, token); }
public void CreateInDatabase(ChargeLevel chargeLevel) { if (chargeLevel == null) { throw new ArgumentNullException(nameof(chargeLevel)); } using (var ipPhoneEntities = new IPPhoneEntities()) { ipPhoneEntities.ChargeLevels.Add(chargeLevel); ipPhoneEntities.SaveChanges(); } }
public void UpdateInDatabase(int id, ContactEntity contactEntity) { if (contactEntity == null) { throw new ArgumentNullException(nameof(contactEntity)); } var contact = contactEntity.ToModel(); using (var ipPhoneEntities = new IPPhoneEntities()) { ipPhoneEntities.SaveChanges(); } }
public void DeleteFromDatabase(int level) { using (var ipPhoneEntities = new IPPhoneEntities()) { var chargeLevel = ipPhoneEntities.ChargeLevels.SingleOrDefault(c => c.Level == level); if (chargeLevel != null) { ipPhoneEntities.ChargeLevels.Remove(chargeLevel); } ipPhoneEntities.SaveChanges(); } }
public List <ChargeLevel> ReadAllFromDatabase(string sort) { using (var ipPhoneEntities = new IPPhoneEntities()) { if (sort == "-level") { return(ipPhoneEntities.ChargeLevels.OrderByDescending(c => c.Level).ToList()); } if (sort == " level") { return(ipPhoneEntities.ChargeLevels.OrderBy(c => c.Level).ToList()); } } return(null); }
public bool IsAuthenticated(string token) { if (token == null) { return(false); } IPPhoneEntities ipphoneEntities = new IPPhoneEntities(); UserToken userToken = ipphoneEntities.UserTokens.Where(c => c.Token.Equals(token) && DateTime.Today < c.ExpiredTime).FirstOrDefault(); if (userToken == null) { return(false); } return(true); }
public void CreateInDatabase(ContactEntity contactEntity) { if (contactEntity == null) { throw new ArgumentNullException(nameof(contactEntity)); } var contact = contactEntity.ToModel(); contact.Id = Guid.NewGuid(); using (var ipPhoneEntities = new IPPhoneEntities()) { ipPhoneEntities.Contacts.Add(contact); ipPhoneEntities.SaveChanges(); } }
public void InsertUserToken(User user, string token) { using (IPPhoneEntities ipphoneEntities = new IPPhoneEntities()) { DateTime today = DateTime.Now.Date; List <UserToken> userExpired = ipphoneEntities.UserTokens.Where(t => t.ExpiredTime < today).ToList(); if (userExpired.Count != 0) { ipphoneEntities.UserTokens.RemoveRange(userExpired); } ipphoneEntities.UserTokens.Add(new UserToken { UserName = user.Name, Token = token, ExpiredTime = today.AddDays(10) }); ipphoneEntities.SaveChanges(); } }
public void UpdateInDatabase(int level, ChargeLevel chargeLevel) { if (chargeLevel == null) { throw new ArgumentNullException(nameof(chargeLevel)); } using (var ipPhoneEntities = new IPPhoneEntities()) { var focusChargeLevel = ipPhoneEntities.ChargeLevels.FirstOrDefault(c => c.Level == chargeLevel.Level); if (focusChargeLevel != null) { focusChargeLevel.Level = chargeLevel.Level; focusChargeLevel.Charge = chargeLevel.Charge; } ipPhoneEntities.SaveChanges(); } }
public UserService() { ipphoneEntities = new IPPhoneEntities(); }