public void UpdatePerson(IPerson person) { var ctx = new AddressBookContext(); var entity = ctx.Persons.Find(person.ID); Mappings.Map(person, entity); ctx.SaveChanges(); }
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); } }
public void InsertPerson(IPerson person) { var ctx = new AddressBookContext(); var entity = new Person(); Mappings.Map(person, entity); ctx.Persons.Add(entity); ctx.SaveChanges(); }
public ContactController() { var context = new AddressBookContext(); _contactLogic = new ContactLogic(new ContactRepository(context)); _contactTypeLogic = new ContactTypeLogic(new ContactTypeRepository(context)); _userLogic = new UserLogic(new UserRepository(context)); }
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); }
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); } } }
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); } }
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); } }
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); } }
public UpdateContact() { _context = new AddressBookContext(); }
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); }
public UserLoginService() { db = new AddressBookContext(); }
public ZipCodeRepository( AddressBookContext dbContext, ILoggerFactory loggerFactory) : base(dbContext, loggerFactory) { }
public AddressBookController(AddressBookContext context) { _context = context; contactService = new ContactService(context); }
public CountryRepository( AddressBookContext dbContext, ILoggerFactory loggerFactory) : base(dbContext, loggerFactory) { }
public ContactsController(AddressBookContext dbContext) { this._dbContext = dbContext; }
public PersonsController(AddressBookContext context) { this.context = context; }
public ContactTypeRepository(AddressBookContext context) : base(context) { }
public UserRepository(AddressBookContext context) : base(context) { }
public ManagePhonesService(AddressBookContext GroupContext) { db = GroupContext; }
public EmployeesController(AddressBookContext context) { _context = context; }
public DeleteContact() { _context = new AddressBookContext(); }
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(); }
public HomeController(AddressBookContext context) { db = context; }
public ContactRepository(AddressBookContext ctx) { _ctx = ctx; }
public AddressesController(ILogger <AddressesController> logger, AddressBookContext context) { _logger = logger; _context = context; }
public ManageAbonentGroupService(AddressBookContext GroupContext) { db = GroupContext; }
public PersonsController(AddressBookContext context, IMapper mapper) { this.context = context; this.mapper = mapper; }
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); } }
public PhoneNumberRepository( AddressBookContext dbContext, ILoggerFactory loggerFactory) : base(dbContext, loggerFactory) { }
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; }
public ContactRepository(AddressBookContext addressBookContext) { this._addressBookContext = addressBookContext; }
public ContactTypeController() { var context = new AddressBookContext(); _contactTypeLogic = new ContactTypeLogic(new ContactTypeRepository(context)); }
public ManageUsersService(AddressBookContext usersContext) { db = usersContext; }
public ContactService(AddressBookContext context) { _context = context; }
public AccountController() { AddressBookContext context = new AddressBookContext(); _userLogic = new UserLogic(new UserRepository(context)); }
public AddressController(AddressBookContext context) { _context = context; }
public PeopleController(AddressBookContext context) { _context = context; }
public UsersController(AddressBookContext context, ManageUsersService usersService) { _context = context; _usersService = usersService; }
public PhoneDirectoryService() { db = new AddressBookContext(); }
public Repository(AddressBookContext context) { db = context; }