Beispiel #1
0
 public void CreateUser(ClaimsIdentity userLogin)
 {
     ipphoneEntities.Users.Add(new User {
         Name = userLogin.Name
     });
     ipphoneEntities.SaveChanges();
 }
Beispiel #2
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();
     }
 }
Beispiel #3
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();
            }
        }
Beispiel #4
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();
            }
        }
Beispiel #5
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();
            }
        }
Beispiel #6
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();
            }
        }
Beispiel #7
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();
            }
        }
Beispiel #8
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();
            }
        }