public void CanAddMembershipUser()
        {
            using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
            {
                context.Context.ExecuteStoreCommand("DELETE FROM MembershipUser");
                FixedAssetService transaction = new FixedAssetService();
                MembershipUser user = new MembershipUser()
                {
                    login = "******",
                    email = "*****@*****.**",
                    creation_date = DateTime.Now,
                    is_online = false,
                    name = "Jan",
                    surname = "Kowalski",
                    is_active = true,
                    last_login_date = DateTime.Now,
                    password = "******"
                };

                transaction.AddMembershipUser(user);
                Assert.AreEqual(context.Context.MembershipUsers.Count(), 1);
                user = context.Context.MembershipUsers.FirstOrDefault(x => x.login == "user123");
                Assert.IsNotNull(user);
            }
        }
        public void CanAddLicence()
        {
            using(EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
            {
                context.Context.ExecuteStoreCommand("DELETE FROM Licence");
                context.Context.ExecuteStoreCommand("DELETE FROM MembershipUser");
                context.Context.ExecuteStoreCommand("DELETE FROM Kind");
                context.Context.ExecuteStoreCommand("DELETE FROM FixedAsset");

                FixedAssetService transaction = new FixedAssetService();
                FixedAsset asset = new FixedAsset()
                {
                    id = 2222,
                    inventory_number = "aaaa",
                    date_of_activation = DateTime.Now,
                    cassation = false
                };

                MembershipUser user = new MembershipUser()
                {
                    login = "******",
                    email = "*****@*****.**",
                    creation_date = DateTime.Now,
                    is_online = false,
                    name = "Jan",
                    surname = "Kowalski",
                    is_active = true,
                    last_login_date = DateTime.Now,
                    password = "******"
                };

                Kind kind = new Kind() { name = "Oprogramowanie" };

                Licence licence = new Licence() { inventory_number = "xxxx", 
                                                  name = "Windows XP",
                                                  created_by = user.login,
                                                  MembershipUser = user,
                                                  FixedAsset = asset,
                                                  Kind = kind,
                                                  last_modified_login = user.login,
                                                  last_modified_date = DateTime.Now
                };

                transaction.AddLicence(licence);
                Assert.AreEqual(context.Context.Licences.Count(), 1);


                licence = context.Context.Licences.FirstOrDefault(x => x.inventory_number == "xxxx");
                Assert.IsNotNull(licence);
                Assert.AreEqual(licence.name, "Windows XP");
            }
        }
        public void CantAddMembershipUser()
        {
            using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
            {
                context.Context.ExecuteStoreCommand("DELETE FROM MembershipUser");
                FixedAssetService transaction = new FixedAssetService();
                MembershipUser user = new MembershipUser()
                {
                    login = "******",
                    name = "Jan",
                    surname = "Kowalski",
                    
                };

                transaction.AddMembershipUser(user);
                Assert.AreEqual(context.Context.MembershipUsers.Count(), 1);
                user = context.Context.MembershipUsers.FirstOrDefault(x => x.login == "user123");
                Assert.IsNotNull(user);
            }
        }
 public void AddMembershipUser(MembershipUser membershipUser)
 {
     using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         try
         {
             context.Context.MembershipUsers.AddObject(membershipUser);
             context.SaveChanges();
         }
         catch (UpdateException)
         {
             throw new FaultException(string.Format(
             "Nie udało się dodać użytkownika. Popraw dane i spróbuj ponownie"));
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message.ToString());
         }
     }
 }
 public void DeleteMembershipUser(MembershipUser membershipUser)
 {
     using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
     {
         try
         {
             context.Context.MembershipUsers.Attach(membershipUser);
             context.Context.MembershipUsers.DeleteObject(membershipUser);
             context.SaveChanges();
         }
         catch (UpdateException)
         {
             throw new FaultException(string.Format(
             "Nie udało się usunąć użytkownika. Prawdopodobnie nie istnieje"));
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message.ToString());
         }
     }
 }
        public void EditMembershipUser(MembershipUser membershipUser)
        {
            using (EF_ZMT_DbContext.EF_ZMT_DbContext context = new EF_ZMT_DbContext.EF_ZMT_DbContext())
            {
                try
                {
                    MembershipUser originalRole = context.Context.MembershipUsers.FirstOrDefault(r => r.login == membershipUser.login);
                    context.Context.MembershipUsers.ApplyCurrentValues(membershipUser);
                    context.SaveChanges();

                }
                catch (UpdateException)
                {
                    throw new FaultException(string.Format(
                    "Nie udało się edytować użytkownika. Popraw dane i spróbuj ponownie"));
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message.ToString());
                }
            }
        }
     private void FixupMembershipUser(MembershipUser previousValue)
     {
         if (IsDeserializing)
         {
             return;
         }
 
         if (previousValue != null && previousValue.Licences.Contains(this))
         {
             previousValue.Licences.Remove(this);
         }
 
         if (MembershipUser != null)
         {
             if (!MembershipUser.Licences.Contains(this))
             {
                 MembershipUser.Licences.Add(this);
             }
 
             created_by = MembershipUser.login;
         }
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("MembershipUser")
                 && (ChangeTracker.OriginalValues["MembershipUser"] == MembershipUser))
             {
                 ChangeTracker.OriginalValues.Remove("MembershipUser");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("MembershipUser", previousValue);
             }
             if (MembershipUser != null && !MembershipUser.ChangeTracker.ChangeTrackingEnabled)
             {
                 MembershipUser.StartTracking();
             }
         }
     }