public static void RemoveReaderHistoryById(int id)
 {
     using (var uow = new LibraryUow())
     {
         uow.ReadersHistories.Delete(id);
         uow.Commit();
     }
 }
 public static void RemoveReaderHistoryById(int id)
 {
     using (var uow = new LibraryUow())
     {
         uow.ReadersHistories.Delete(id);
         uow.Commit();
     }
 }
        public ConsignmentBusinessModel CreateConsignment(int itemId, ConsignmentBusinessModel consignment)
        {
            ConsignmentBusinessModel consNew;
            var mapper = new ConsignmentMapper();

            int id = 0;
            using (var uowNew = new LibraryUow())
            {
                var item = uowNew.Items.GetById(itemId);
                var entryConsignment = mapper.Map(consignment);
                entryConsignment.Item = item;
                uowNew.Consignments.Add(entryConsignment);

                uowNew.Commit();
                id = entryConsignment.Id;
            }

            consNew = mapper.Map(this.uow.Consignments.GetById(id));
            consignment.Id = consNew.Id;
            consignment.Number = consNew.Number;
            return consNew;
        }
        public ConsignmentBusinessModel CreateConsignment(int itemId, ConsignmentBusinessModel consignment)
        {
            ConsignmentBusinessModel consNew;
            var mapper = new ConsignmentMapper();

            int id = 0;

            using (var uowNew = new LibraryUow())
            {
                var item             = uowNew.Items.GetById(itemId);
                var entryConsignment = mapper.Map(consignment);
                entryConsignment.Item = item;
                uowNew.Consignments.Add(entryConsignment);

                uowNew.Commit();
                id = entryConsignment.Id;
            }

            consNew            = mapper.Map(this.uow.Consignments.GetById(id));
            consignment.Id     = consNew.Id;
            consignment.Number = consNew.Number;
            return(consNew);
        }
            private void InitializeData()
            {
                if (!Roles.RoleExists("Admin"))
                {
                    Roles.CreateRole("Admin");
                }

                if (!Roles.RoleExists("Librarian"))
                {
                    Roles.CreateRole("Librarian");
                }

                if (!Roles.RoleExists("Registered"))
                {
                    Roles.CreateRole("Registered");
                }

                if (!Roles.RoleExists("Unregistered"))
                {
                    Roles.CreateRole("Unregistered");
                }

                LibraryUow uow = new LibraryUow();

                if (!WebSecurity.UserExists("admin"))
                {
                    WebSecurity.CreateUserAndAccount("admin", "Pa$$word");
                    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("admin"));
                    user.Email = "*****@*****.**";
                    Roles.AddUserToRole("admin", "Admin");
                }

                if (!WebSecurity.UserExists("librarian"))
                {
                    WebSecurity.CreateUserAndAccount("librarian", "123456");
                    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("librarian"));
                    user.Email = "*****@*****.**";
                    Roles.AddUserToRole("librarian", "Librarian");
                }

                if (!WebSecurity.UserExists("yarkip"))
                {
                    WebSecurity.CreateUserAndAccount("yarkip", "123456");
                    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("yarkip"));
                    user.Email = "*****@*****.**";
                    Roles.AddUserToRole("yarkip", "Registered");
                }

                //if (!WebSecurity.UserExists("mykola"))
                //{
                //    WebSecurity.CreateUserAndAccount("mykola", "123456");
                //    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("mykola"));
                //    user.Email = "*****@*****.**";
                //    //Roles.AddUserToRole("mykola", "Registered");
                //}

                //if (!WebSecurity.UserExists("kola"))
                //{
                //    WebSecurity.CreateUserAndAccount("kola", "123456");
                //    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("kola"));
                //    user.Email = "*****@*****.**";
                //    //Roles.AddUserToRole("kola", "Registered");
                //}

                if (!WebSecurity.UserExists("mike"))
                {
                    WebSecurity.CreateUserAndAccount("mike", "123456");
                    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("mike"));
                    user.Email = "*****@*****.**";
                }

                if (!WebSecurity.UserExists("bob"))
                {
                    WebSecurity.CreateUserAndAccount("bob", "123456");
                    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("bob"));
                    user.Email = "*****@*****.**";
                }

                if (!WebSecurity.UserExists("rick"))
                {
                    WebSecurity.CreateUserAndAccount("rick", "123456");
                    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("rick"));
                    user.Email = "*****@*****.**";
                }

                //test reader
                if (!WebSecurity.UserExists("alice"))
                {
                    WebSecurity.CreateUserAndAccount("alice", "123456");
                    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("alice"));
                    user.Email = "*****@*****.**";
                }

                if (Roles.GetRolesForUser("alice").Length == 0)
                {
                    Roles.AddUserToRole("alice", "Unregistered");
                }

                if (Roles.GetRolesForUser("mike").Length == 0)
                {
                    Roles.AddUserToRole("mike", "Unregistered");
                }

                if (Roles.GetRolesForUser("bob").Length == 0)
                {
                    Roles.AddUserToRole("bob", "Registered");
                }

                if (Roles.GetRolesForUser("rick").Length == 0)
                {
                    Roles.AddUserToRole("rick", "Unregistered");
                }

                uow.Commit();

            }
Exemple #6
0
            private void InitializeData()
            {
                if (!Roles.RoleExists("Admin"))
                {
                    Roles.CreateRole("Admin");
                }

                if (!Roles.RoleExists("Librarian"))
                {
                    Roles.CreateRole("Librarian");
                }

                if (!Roles.RoleExists("Registered"))
                {
                    Roles.CreateRole("Registered");
                }

                if (!Roles.RoleExists("Unregistered"))
                {
                    Roles.CreateRole("Unregistered");
                }

                LibraryUow uow = new LibraryUow();

                if (!WebSecurity.UserExists("admin"))
                {
                    WebSecurity.CreateUserAndAccount("admin", "Pa$$word");
                    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("admin"));
                    user.Email = "*****@*****.**";
                    Roles.AddUserToRole("admin", "Admin");
                }

                if (!WebSecurity.UserExists("librarian"))
                {
                    WebSecurity.CreateUserAndAccount("librarian", "123456");
                    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("librarian"));
                    user.Email = "*****@*****.**";
                    Roles.AddUserToRole("librarian", "Librarian");
                }

                if (!WebSecurity.UserExists("yarkip"))
                {
                    WebSecurity.CreateUserAndAccount("yarkip", "123456");
                    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("yarkip"));
                    user.Email = "*****@*****.**";
                    Roles.AddUserToRole("yarkip", "Registered");
                }

                //if (!WebSecurity.UserExists("mykola"))
                //{
                //    WebSecurity.CreateUserAndAccount("mykola", "123456");
                //    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("mykola"));
                //    user.Email = "*****@*****.**";
                //    //Roles.AddUserToRole("mykola", "Registered");
                //}

                //if (!WebSecurity.UserExists("kola"))
                //{
                //    WebSecurity.CreateUserAndAccount("kola", "123456");
                //    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("kola"));
                //    user.Email = "*****@*****.**";
                //    //Roles.AddUserToRole("kola", "Registered");
                //}

                if (!WebSecurity.UserExists("mike"))
                {
                    WebSecurity.CreateUserAndAccount("mike", "123456");
                    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("mike"));
                    user.Email = "*****@*****.**";
                }

                if (!WebSecurity.UserExists("bob"))
                {
                    WebSecurity.CreateUserAndAccount("bob", "123456");
                    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("bob"));
                    user.Email = "*****@*****.**";
                }

                if (!WebSecurity.UserExists("rick"))
                {
                    WebSecurity.CreateUserAndAccount("rick", "123456");
                    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("rick"));
                    user.Email = "*****@*****.**";
                }

                //test reader
                if (!WebSecurity.UserExists("alice"))
                {
                    WebSecurity.CreateUserAndAccount("alice", "123456");
                    UserProfile user = uow.UsersProfiles.GetById(WebSecurity.GetUserId("alice"));
                    user.Email = "*****@*****.**";
                }

                if (Roles.GetRolesForUser("alice").Length == 0)
                {
                    Roles.AddUserToRole("alice", "Unregistered");
                }

                if (Roles.GetRolesForUser("mike").Length == 0)
                {
                    Roles.AddUserToRole("mike", "Unregistered");
                }

                if (Roles.GetRolesForUser("bob").Length == 0)
                {
                    Roles.AddUserToRole("bob", "Registered");
                }

                if (Roles.GetRolesForUser("rick").Length == 0)
                {
                    Roles.AddUserToRole("rick", "Unregistered");
                }

                uow.Commit();
            }