Exemplo n.º 1
0
 public ChargeLevel ReadFromDatabase(int level)
 {
     using (var ipPhoneEntities = new IPPhoneEntities())
     {
         return(ipPhoneEntities.ChargeLevels.SingleOrDefault(c => c.Level == level));
     }
 }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
 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();
     }
 }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public void CreateInDatabase(ChargeLevel chargeLevel)
        {
            if (chargeLevel == null)
            {
                throw new ArgumentNullException(nameof(chargeLevel));
            }

            using (var ipPhoneEntities = new IPPhoneEntities())
            {
                ipPhoneEntities.ChargeLevels.Add(chargeLevel);

                ipPhoneEntities.SaveChanges();
            }
        }
Exemplo n.º 6
0
        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();
            }
        }
Exemplo n.º 7
0
        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();
            }
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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();
            }
        }
Exemplo n.º 11
0
        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();
            }
        }
Exemplo n.º 12
0
        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();
            }
        }
Exemplo n.º 13
0
 public UserService()
 {
     ipphoneEntities = new IPPhoneEntities();
 }