Ejemplo n.º 1
0
 public void UpdatePerson(IPerson person)
 {
     var ctx = new AddressBookContext();
     var entity = ctx.Persons.Find(person.ID);
     Mappings.Map(person, entity);
     ctx.SaveChanges();
 }
Ejemplo n.º 2
0
 public void DeletePerson(int personID)
 {
     var ctx = new AddressBookContext();
     var person = ctx.Persons.Find(personID);
     ctx.Persons.Remove(person);
     ctx.SaveChanges();
 }
            public SimpleMembershipInitializer()
            {
                Database.SetInitializer<AddressBookContext>(null);

                try
                {
                    using (var context = new AddressBookContext())
                    {
                        if (!context.Database.Exists())
                        {
                            // Create the SimpleMembership database without Entity Framework migration schema
                            ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                        }
                    }

                    WebSecurity.InitializeDatabaseConnection("AddressBookConnection", "User", "UserId", "UserLogin", autoCreateTables: true);

                    defaultInit.CreateRoles();
                    defaultInit.CreateAdmin();

                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
                }
            }
Ejemplo n.º 4
0
 public void InsertPerson(IPerson person)
 {
     var ctx = new AddressBookContext();
     var entity = new Person();
     Mappings.Map(person, entity);
     ctx.Persons.Add(entity);
     ctx.SaveChanges();
 }
Ejemplo n.º 5
0
        public ContactController()
        {
            var context = new AddressBookContext();

            _contactLogic = new ContactLogic(new ContactRepository(context));
            _contactTypeLogic = new ContactTypeLogic(new ContactTypeRepository(context));
            _userLogic = new UserLogic(new UserRepository(context));
        }
Ejemplo n.º 6
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            AddressBookContext usersContext = new AddressBookContext();
            var user = usersContext.Users.FirstOrDefault(u => u.UserLogin == model.UserLogin);
            //var user = usersContext.Users.Single(u => u.UserLogin == model.UserLogin);

            if (ModelState.IsValid  && user.UserConfirmedEmail==true)
            {
                if (WebSecurity.Login(model.UserLogin, model.Password, persistCookie: model.RememberMe))
                {
                    return RedirectToLocal(returnUrl);
                }
                
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }
Ejemplo n.º 7
0
        public void CreateContact(CreateEditContact contact, string uploadPathBase)
        {
            using (var context = new AddressBookContext(nameOrConnectionString))
            {
                if (contact.File != null && contact.File.ContentLength > 0)
                {
                    contact.Image = Guid.NewGuid() + Path.GetExtension(contact.File.FileName);                    
                    contact.File.SaveAs(Path.Combine(uploadPathBase, contact.Image));
                }

                var mapped = new DataAccess.Models.Contact
                {
                    Id = contact.Id,
                    FullName = contact.FullName,
                    LastName = contact.LastName,
                    Title = contact.Title,
                    Email = contact.Email,
                    OfficeId = contact.OfficeId,
                    DepartmentId = contact.DepartmentId,
                    OrganisationId = contact.OrganisationId,
                    Image = contact.Image,
                    WebLinks = contact.WebLinks
                        .Where(w => !string.IsNullOrWhiteSpace(w.Url))
                        .Select(w => new WebLink {  Id = w.Id, ContactId = w.ContactId, WebLinkTypeId = w.WebLinkTypeId})
                        .ToList(),
                    PhoneNumbers = contact.PhoneNumbers
                        .Where(p => !string.IsNullOrWhiteSpace(p.PhoneNumber))
                        .Select(p => new ContactPhoneNumber {  Id = p.Id, ContactId = p.ContactId, PhoneNumberTypeId = p.PhoneNumberTypeId})
                        .ToList()
                };

                context.Contacts.Add(mapped);
                context.SaveChanges();

                // Update the lucene index
                var luceneUpdate = new CreateUpdateLuceneContact(mapped);
                luceneUpdate.Execute();
            }
        }
        public void InitializeIndex()
        {
            var context = new AddressBookContext(connectionString);
            var contacts = context.Contacts
                .Include(c => c.Organisation)
                .Include(c => c.Department)
                .Include(c => c.Office.Address)
                .Include(c => c.PhoneNumbers)
                .Include(c => c.EmailAddresses);
            
            using (var provider = new LuceneDataProvider(LuceneSearch.LuceneDirectory, Lucene.Net.Util.Version.LUCENE_30))
            {
                provider.Settings.EnableMultipleEntities = false;

                using (var session = provider.OpenSession<ContactDocument>())
                {
                    var docs = contacts.Select(LuceneSearch.MapContactToDocument).ToArray();
                    
                    session.DeleteAll();
                    session.Add(docs);
                }
            }            
        }
Ejemplo n.º 9
0
        public PagedContactQueryResult GetContactsByStateAndLastName(string state, string lastName, int page,
            int pageSize)
        {
            using (var context = new AddressBookContext(nameOrConnectionString))
            {
                var contacts = context.Contacts
                    .Where(c => c.Office.Address.State == state)
                    .Where(c => c.LastName.StartsWith(lastName))
                    .Include(c => c.PhoneNumbers.Select(w => w.PhoneNumberType))
                    .Include(c => c.Organisation)
                    .Include(c => c.Department)
                    .Include(c => c.Office.Address)
                    .Include(c => c.WebLinks.Select(w => w.WebLinkType))
                    .OrderBy(c => c.LastName)
                    .ThenBy(c => c.Office.Address.State)
                    .Skip((page - 1) * pageSize)
                    .Take(pageSize)
                    .Select(MapContact)
                    .ToList();

                var count = context.Contacts
                    .Where(c => c.Office.Address.State == state)
                    .Count(c => c.LastName.StartsWith(lastName));

                return new PagedContactQueryResult(page, pageSize, count, contacts);
            }
        }
Ejemplo n.º 10
0
        public PagedContactQueryResult GetContacts(int page = 1, int pageSize = 50)
        {
            using (var context = new AddressBookContext(nameOrConnectionString))
            {
                var contacts = context.Contacts
                    .OrderBy(c => c.LastName)
                    .Skip((page - 1) * pageSize)
                    .Take(pageSize)
                    .Include(c => c.PhoneNumbers.Select(w => w.PhoneNumberType))
                    .Include(c => c.Organisation)
                    .Include(c => c.Department)
                    .Include(c => c.Office)
                    .Include(c => c.WebLinks.Select(w => w.WebLinkType))
                    .Select(MapContact)
                    .ToList();

                var count = context.Contacts.Count();

                return new PagedContactQueryResult(page, pageSize, count, contacts);
            }
        }
Ejemplo n.º 11
0
 public ContactViewModel GetContactDetails(int id)
 {
     using (var context = new AddressBookContext(nameOrConnectionString))
     {
         return context
             .Contacts
             .Include(c => c.PhoneNumbers.Select(w => w.PhoneNumberType))
             .Include(c => c.Organisation)
             .Include(c => c.Department)
             .Include(c => c.Office)
             .Include(c => c.WebLinks.Select(w => w.WebLinkType))
             .Select(MapContact)
             .FirstOrDefault(contact => contact.Id == id);
     }
 }
Ejemplo n.º 12
0
 public UpdateContact()
 {
     _context = new AddressBookContext();
 }
Ejemplo n.º 13
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (AddressBookContext db = new AddressBookContext())
                {
                    User user = db.Users.FirstOrDefault(u => u.UserLogin.ToLower() == model.UserLogin.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.Users.Add(new User { UserLogin = model.UserLogin });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserLogin);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return RedirectToLocal(returnUrl);
                    }
                    else
                    {
                        ModelState.AddModelError("UserLogin", "User login already exists. Please enter a different user login.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
Ejemplo n.º 14
0
 public UserLoginService()
 {
     db = new AddressBookContext();
 }
Ejemplo n.º 15
0
 public ZipCodeRepository(
     AddressBookContext dbContext,
     ILoggerFactory loggerFactory)
     : base(dbContext, loggerFactory)
 {
 }
 public AddressBookController(AddressBookContext context)
 {
     _context       = context;
     contactService = new ContactService(context);
 }
Ejemplo n.º 17
0
 public CountryRepository(
     AddressBookContext dbContext,
     ILoggerFactory loggerFactory)
     : base(dbContext, loggerFactory)
 {
 }
Ejemplo n.º 18
0
 public ContactsController(AddressBookContext dbContext)
 {
     this._dbContext = dbContext;
 }
Ejemplo n.º 19
0
 public PersonsController(AddressBookContext context)
 {
     this.context = context;
 }
Ejemplo n.º 20
0
 public ContactTypeRepository(AddressBookContext context) : base(context)
 {
 }
Ejemplo n.º 21
0
 public UserRepository(AddressBookContext context) : base(context)
 {
 }
Ejemplo n.º 22
0
 public ManagePhonesService(AddressBookContext GroupContext)
 {
     db = GroupContext;
 }
Ejemplo n.º 23
0
 public EmployeesController(AddressBookContext context)
 {
     _context = context;
 }
 public DeleteContact()
 {
     _context = new AddressBookContext();
 }
Ejemplo n.º 25
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    var user = new User() { UserLogin = model.UserLogin };
                    user.UserEmail = model.UserEmail;
                    user.UserConfirmedEmail = false;                

                    WebSecurity.CreateUserAndAccount(model.UserLogin, model.Password,
                        new
                        {
                            UserName = model.UserName,
                            UserSurname = model.UserSurname,
                            UserMidName = model.UserMidName,
                            UserEmail = model.UserEmail,
                            UserComment = model.UserComment,
                            UserPhoneNumber = model.UserPhoneNumber,
                            UserPassword = model.Password,
                            UserLogin = model.UserLogin,
                            //UserConfirmedEmail=false
                            UserConfirmedEmail = true
                        });

                    AddressBookContext usersContext = new AddressBookContext();
                    var userTwo = usersContext.Users.SingleOrDefault(u => u.UserLogin == model.UserLogin);

                    MailHelper mailHelper = new MailHelper();

                    userTwo.UserConfirmString = mailHelper.GetConfirmString();
                    usersContext.SaveChanges();

                    //contactHelper.SendMail(user.UserEmail, userTwo.UserLogin, userTwo.UserConfirmString);

                    //return RedirectToAction("Info", "Home");
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
 public SearchContact()
 {
     _context = new AddressBookContext();
 }
Ejemplo n.º 27
0
 public HomeController(AddressBookContext context)
 {
     db = context;
 }
Ejemplo n.º 28
0
 public ContactRepository(AddressBookContext ctx)
 {
     _ctx = ctx;
 }
Ejemplo n.º 29
0
 public ContactTypeRepository(AddressBookContext context) : base(context)
 {
 }
 public AddressesController(ILogger <AddressesController> logger, AddressBookContext context)
 {
     _logger  = logger;
     _context = context;
 }
Ejemplo n.º 31
0
 public ManageAbonentGroupService(AddressBookContext GroupContext)
 {
     db = GroupContext;
 }
 public PersonsController(AddressBookContext context, IMapper mapper)
 {
     this.context = context;
     this.mapper  = mapper;
 }
Ejemplo n.º 33
0
        public PagedContactQueryResult SearchContacts(string searchTerm, int page = 1, int pageSize = 50)
        {
            var luceneSearcher = new SingleTermLuceneSearcher();

            using (var context = new AddressBookContext(nameOrConnectionString))
            {
                var luceneResults = luceneSearcher.Search(searchTerm).Results;

                var contacts = luceneResults
                    .OrderBy(r => r.LastName)
                    .Skip((page - 1) * pageSize)
                    .Take(pageSize)
                    .Select(record => context.Contacts
                        .Include(c => c.PhoneNumbers.Select(p => p.PhoneNumberType))
                        .Include(c => c.Organisation)
                        .Include(c => c.Department)
                        .Include(c => c.Office)
                        .Include(c => c.WebLinks.Select(w => w.WebLinkType))
                        .FirstOrDefault(c => c.Id == record.Id))
                    .Where(record => record != null)
                    .Select(MapContact)
                    .ToList();

                var count = luceneResults.Count();

                return new PagedContactQueryResult(page, pageSize, count, contacts);
            }
        }
Ejemplo n.º 34
0
 public PhoneNumberRepository(
     AddressBookContext dbContext,
     ILoggerFactory loggerFactory)
     : base(dbContext, loggerFactory)
 {
 }
Ejemplo n.º 35
0
        public void UpdateContact(CreateEditContact contact, string uploadPath)
        {
            var mappedContact = new DataAccess.Models.Contact
            {
                Id = contact.Id,
                FullName = contact.FullName,
                LastName = contact.LastName,
                Email = contact.Email,
                Title = contact.Title,
                DepartmentId = contact.DepartmentId,
                OfficeId = contact.OfficeId,
                OrganisationId = contact.OrganisationId,
                Image = contact.Image,
                PhoneNumbers = contact.PhoneNumbers
                    .Where(p => !string.IsNullOrWhiteSpace(p.PhoneNumber))
                    .Select(p => new ContactPhoneNumber {  Id = p.Id, ContactId = p.ContactId, PhoneNumber = p.PhoneNumber, PhoneNumberTypeId = p.PhoneNumberTypeId})
                    .ToList(),
                WebLinks = contact.WebLinks
                    .Where(w => !string.IsNullOrWhiteSpace(w.Url))
                    .Select(w => new WebLink {  Id = w.Id, ContactId = w.ContactId, Url = w.Url, WebLinkTypeId = w.WebLinkTypeId})
                    .ToList()
            };

            using (var context = new AddressBookContext(nameOrConnectionString))
            {
                var originalContact = context
                    .Contacts
                    .Include(c => c.PhoneNumbers)
                    .Include(c => c.WebLinks)
                    .FirstOrDefault(c => c.Id == mappedContact.Id);

                if (originalContact == null)
                    throw new Exception($"No contact with id {mappedContact.Id} exists");

                var originalPhoneNumbers = originalContact
                    .PhoneNumbers
                    .ToList();

                var deletedPhoneNumbers = originalPhoneNumbers
                    .Except(mappedContact.PhoneNumbers, c => c.Id)
                    .ToList();

                var addedPhoneNumbers = mappedContact
                    .PhoneNumbers
                    .Where(p => p.Id == 0)
                    .ToList();

                var modifiedPhoneNumbers = mappedContact
                    .PhoneNumbers
                    .Except(deletedPhoneNumbers, c => c.Id)
                    .Except(addedPhoneNumbers, c => c.Id)
                    .ToList();

                foreach (var delete in deletedPhoneNumbers)
                {
                    context.Entry(delete).State = EntityState.Deleted;
                }

                foreach (var added in addedPhoneNumbers)
                {
                    context.Entry(added).State = EntityState.Added;
                }

                // Get existing items to update
                foreach (var modified in modifiedPhoneNumbers)
                {
                    var existing = context.PhoneNumbers.Find(modified.Id);
                    if (existing == null)
                        continue;

                    context.Entry(existing).CurrentValues.SetValues(modified);
                }

                var originalWebLinks = originalContact
                    .WebLinks
                    .ToList();

                var deletedWebLinks = originalWebLinks
                    .Except(mappedContact.WebLinks, c => c.Id)
                    .ToList();

                var addedWebLinks = mappedContact.WebLinks
                    .Where(c => c.Id == 0)
                    .ToList();

                var modifiedWebLinks = mappedContact.WebLinks
                    .Except(deletedWebLinks, c => c.Id)
                    .Except(addedWebLinks, c => c.Id)
                    .ToList();

                foreach (var delete in deletedWebLinks)
                {
                    context.Entry(delete).State = EntityState.Deleted;
                }

                foreach (var added in addedWebLinks)
                {
                    context.Entry(added).State = EntityState.Added;
                }

                // Get existing items to update
                foreach (var modified in modifiedWebLinks)
                {
                    var existing = context.WebLinks.Find(modified.Id);
                    if (existing == null)
                        continue;

                    context.Entry(existing).CurrentValues.SetValues(modified);
                }

                // If we have an image attached
                if (contact.File != null && contact.File.ContentLength > 0)
                {
                    var uploadedImageName = Guid.NewGuid() + Path.GetExtension(contact.File.FileName);

                    mappedContact.Image = uploadedImageName;

                    contact.File.SaveAs(Path.Combine(uploadPath, uploadedImageName));

                    // Delete the original
                    DeleteImage(originalContact.Image, uploadPath);
                }

                // If no image is attached it means it should be deleted (if possible)
                if (string.IsNullOrWhiteSpace(contact.Image))
                {
                    // Delete the original
                    DeleteImage(originalContact.Image, uploadPath);
                }

                // Update the other properties with the new values
                context.Entry(originalContact).CurrentValues.SetValues(mappedContact);

                context.SaveChanges();

                // Update the lucene index
                var luceneUpdate = new CreateUpdateLuceneContact(mappedContact);
                luceneUpdate.Execute();
            }
        }
 public AddressBookService(AddressBookContext context)
 {
     this.context = context;
 }
Ejemplo n.º 37
0
 public ContactRepository(AddressBookContext addressBookContext)
 {
     this._addressBookContext = addressBookContext;
 }
Ejemplo n.º 38
0
 public UserRepository(AddressBookContext context) : base(context)
 { }
Ejemplo n.º 39
0
        public ContactTypeController()
        {
            var context = new AddressBookContext();

            _contactTypeLogic = new ContactTypeLogic(new ContactTypeRepository(context));
        }
Ejemplo n.º 40
0
 public ManageUsersService(AddressBookContext usersContext)
 {
     db = usersContext;
 }
 public ContactService(AddressBookContext context)
 {
     _context = context;
 }
Ejemplo n.º 42
0
        public AccountController()
        {
            AddressBookContext context = new AddressBookContext();

            _userLogic = new UserLogic(new UserRepository(context));
        }
Ejemplo n.º 43
0
 public AddressController(AddressBookContext context)
 {
     _context = context;
 }
Ejemplo n.º 44
0
 public PeopleController(AddressBookContext context)
 {
     _context = context;
 }
Ejemplo n.º 45
0
 public AccountController()
 {
     AddressBookContext context = new AddressBookContext();
                 
     _userLogic = new UserLogic(new UserRepository(context));
 }
Ejemplo n.º 46
0
 public UsersController(AddressBookContext context, ManageUsersService usersService)
 {
     _context      = context;
     _usersService = usersService;
 }
Ejemplo n.º 47
0
 public PhoneDirectoryService()
 {
     db = new AddressBookContext();
 }
Ejemplo n.º 48
0
 public Repository(AddressBookContext context)
 {
     db = context;
 }