public ActionResult Create(Contact contact)
        {
            db.Contacts.Add(contact);
            db.SaveChanges();

            return RedirectToAction("Index");
        }
Пример #2
0
 public void Delete(int contactId)
 {
     using (var dataContext = new ApplicationDbContext())
      {
     var contactToDelete = new Contact() { UserId = contactId };
     dataContext.Contacts.Attach(contactToDelete);
     dataContext.Contacts.Remove(contactToDelete);
     dataContext.SaveChanges();
      }
 }
Пример #3
0
 public void OnContactInfoChanged(string oldInfo, string newInfo, Contact c)
 {
     if (oldInfo != null)
     {
         removeValue(oldInfo, c, searchDictionary);
     }
     if (newInfo != null)
     {
         insertValue(newInfo, c, searchDictionary);
     }
 }
Пример #4
0
 public int AddData(string firstName, string lastName, string userName, string password, string street, string phoneNumber, string locationId, string roleName)
 {
     var contact = new Contact()
      {
     FirstName = firstName,
     LastName = lastName,
     UserName = userName,
     Password =  password,
     Street = street,
     PhoneNumber = phoneNumber,
     ZipLocationId = Convert.ToInt32(locationId),
     RoleName = roleName
      };
      return _contactService.Insert(contact);
 }
Пример #5
0
        public void DuplicityTest()
        {
            SearchablePhoneBook spb = new SearchablePhoneBook();
            Contact c = new Contact("John Johansson");
            Contact c1 = new Contact("John Johansson");
            Contact c2 = new Contact("John Johansson");
            spb.addContact(c);
            spb.addContact(c1);
            spb.addContact(c2);

            spb.removeContact(c1);

            Assert.AreEqual(spb.Contacts.Count, 2);
            Assert.IsTrue(spb.Contacts.Contains(c));
            Assert.IsTrue(!spb.Contacts.Contains(c1));
            Assert.IsTrue(spb.Contacts.Contains(c2));
        }
Пример #6
0
        public void RemoveTest()
        {
            SearchablePhoneBook spb = new SearchablePhoneBook();
            Contact c = new Contact("John Johansson");
            Contact c2 = new Contact("Karl Johansson");
            Contact c3 = new Contact("Peter Johansson");
            Contact c4 = new Contact("Hans Johansson");
            spb.addContact(c);
            spb.addContact(c2);
            spb.addContact(c3);
            spb.addContact(c4);

            spb.removeContact(c2);
            spb.removeContact(c4);

            Assert.AreEqual(spb.Contacts.Count, 2);
            Assert.IsTrue(spb.Contacts.Any(x => x.Name.StartsWith("John")));
            Assert.IsTrue(spb.Contacts.Any(x => x.Name.StartsWith("Peter")));
        }
Пример #7
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
           if (ModelState.IsValid)
           {
              var user = new Contact() { UserName = model.UserName , FirstName = model.FirstName, LastName = model.LastName, Password = model.Password, ZipLocationId = 1, RoleName = "User"};
              var result = await UserManager.CreateAsync(user, model.Password);
              if (result.Succeeded)
              {
                 await SignInAsync(user, isPersistent: false);
                 return RedirectToAction("Index", "Home");
              }
              else
              {
                 AddErrors(result);
              }
           }

           // If we got this far, something failed, redisplay form
           return View(model);
        }
Пример #8
0
        public void SearchAddressTest()
        {
            SearchablePhoneBook spb = new SearchablePhoneBook();
            Contact c = new Contact("John Johansson");
            c.addAddress(new Address("Sverige", "Göteborg", "Kungsgatan", 0));
            c.addAddress(new Address("Sverige", "Göteborg", "Drottningsgatan", 0));
            c.addAddress(new Address("Sverige", "Göteborg", "Parken", 0));

            Contact c1 = new Contact("John Johansson");
            Contact c2 = new Contact("John Johansson");
            Contact c3 = new Contact("Hans Johansson");
            Contact c4 = new Contact("Karl Johansson");
            spb.addContact(c);
            spb.addContact(c1);
            spb.addContact(c2);
            spb.addContact(c3);
            spb.addContact(c4);

            Assert.AreEqual(spb.Search("Ku").Count, 1);
            Assert.AreEqual(spb.Search("Ku").FirstOrDefault(), c);
        }
Пример #9
0
        public void addContact(Contact c)
        {
            c.addChangedListener(this);
            contactList.Add(c);

            insertValue(c.Name, c, searchDictionary);
            foreach (Address a in c.Addresses)
            {
                insertValue(a.City, c, searchDictionary);
                insertValue(a.Country, c, searchDictionary);
                insertValue(a.Street, c, searchDictionary);
            }

            foreach (Number n in c.Numbers)
            {
                insertValue(n.PhoneNumber, c, searchDictionary);
            }

            foreach (Email e in c.Emails)
            {
                insertValue(e.EmailAddress, c, searchDictionary);
            }
        }
Пример #10
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new Contact() { UserName = model.UserName };
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInAsync(user, isPersistent: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
Пример #11
0
 public ActionResult Edit(Contact contact)
 {
     try
      {
     if (ModelState.IsValid)
     {
         ViewBag.LocationId = new SelectList(_zipLocationService.GetAll(), "Id", "City", contact.ZipLocationId);
        _contactService.Update(contact);
        return RedirectToAction("Index");
     }
      }
      catch (DataException)
      {
     ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
      }
      return View(contact);
 }
Пример #12
0
 public int Insert(Contact contact)
 {
     using (var dataContext = new ApplicationDbContext())
      {
     dataContext.Contacts.Add(contact);
     dataContext.SaveChanges();
     return Convert.ToInt32(contact.UserId);
      }
 }
Пример #13
0
        public void TestFieldListenersTest()
        {
            SearchablePhoneBook spb = new SearchablePhoneBook();
            Contact c = new Contact("John Johansson");

            spb.addContact(c);

            Assert.AreEqual(spb.Search("Jo").Count, 1);

            c.addAddress(new Address("Sverige", "Göteborg", "Kungsgatan", 0));

            Assert.AreEqual(spb.Search("Ku").Count, 1);

            c.addEmail(new Email("*****@*****.**", ContactType.WORK, 0));

            Assert.AreEqual(spb.Search("sten").Count, 1);

            c.removeAddress(c.Addresses.ElementAt(0));

            Assert.AreEqual(spb.Search("Ku").Count, 0);
            Assert.AreEqual(spb.Search("sten").Count, 1);
        }
Пример #14
0
        public void SearchTest()
        {
            SearchablePhoneBook spb = new SearchablePhoneBook();
            Contact c = new Contact("John Johansson");
            Contact c1 = new Contact("John Johansson");
            Contact c2 = new Contact("John Johansson");
            spb.addContact(c);
            spb.addContact(c1);
            spb.addContact(c2);

            Assert.AreEqual(spb.Search("Jo").Count, 3);
        }
Пример #15
0
        public void SearchMultipleFieldsTest()
        {
            SearchablePhoneBook spb = new SearchablePhoneBook();
            Contact c = new Contact("John Johansson");
            c.addAddress(new Address("Sverige", "Göteborg", "Kungsgatan", 0));
            c.addAddress(new Address("Sverige", "Göteborg", "Drottningsgatan", 0));
            c.addAddress(new Address("Sverige", "Göteborg", "Parken", 0));
            c.addEmail(new Email("*****@*****.**", ContactType.WORK, 0));

            Contact c1 = new Contact("John Johansson");
            c1.addAddress(new Address("Sverige", "Göteborg", "Kugsten 15", 0));

            Contact c2 = new Contact("John Johansson");
            c2.addNumber(new Number("Kugge 0720564", ContactType.WORK, 0));

            Contact c3 = new Contact("Hans Johansson");
            c3.addEmail(new Email("*****@*****.**", ContactType.WORK, 0));

            Contact c4 = new Contact("Karl Johansson");
            c4.addEmail(new Email("*****@*****.**",ContactType.HOME,0));

            spb.addContact(c);
            spb.addContact(c1);
            spb.addContact(c2);
            spb.addContact(c3);
            spb.addContact(c4);

            Assert.AreEqual(spb.Search("Ku").Count, 5);
        }
Пример #16
0
        public void SearchManyTest()
        {
            SearchablePhoneBook spb = new SearchablePhoneBook();
            Contact c = new Contact("John Johansson");
            Contact c1 = new Contact("John Johansson");
            Contact c2 = new Contact("John Johansson");
            Contact c3 = new Contact("Hans Johansson");
            Contact c4 = new Contact("Karl Johansson");
            spb.addContact(c);
            spb.addContact(c1);
            spb.addContact(c2);
            spb.addContact(c3);
            spb.addContact(c4);

            Assert.AreEqual(spb.Search("Jo").Count, 3);
            Assert.AreEqual(spb.Search("Ha").Count, 1);
            Assert.AreEqual(spb.Search("Ka").Count, 1);
        }
Пример #17
0
        void windowsUIButtonPanel_ButtonClick(object sender, DevExpress.XtraBars.Docking2010.ButtonEventArgs e)
        {
            if (e.Button.Properties.Caption == "چاپ")
            {
                gridControl.ShowRibbonPrintPreview();
            }

            if (e.Button.Properties.Caption == "جدید")
            {
                Infrastructure.Utility.AddNewContactForm.addButton.Enabled  = true;
                Infrastructure.Utility.AddNewContactForm.editButton.Enabled = false;

                Infrastructure.Utility.AddNewContactForm.ShowDialog();

                SearchContact();
            }

            if (e.Button.Properties.Caption == "بروزرسانی")
            {
                SearchContact();
                DevExpress.XtraEditors.XtraMessageBox.Show("به روز رسانی انجام شد");
            }

            if (e.Button.Properties.Caption == "اصلاح")
            {
                if (gridView.SelectedRowsCount != 1)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("برای اصلاح فقط یک آیتم را انتخاب کنید");
                    return;
                }

                // first get selected rows indexes to var and then cast it to model
                int[] selectedRows = gridView.GetSelectedRows();

                Models.Contact selectedContact =
                    gridView.GetRow(selectedRows[0]) as Models.Contact;

                if (selectedContact != null)
                {
                    Infrastructure.Utility.AddNewContactForm.SelectedContact = selectedContact;

                    Infrastructure.Utility.AddNewContactForm.addButton.Enabled  = false;
                    Infrastructure.Utility.AddNewContactForm.editButton.Enabled = true;

                    Infrastructure.Utility.AddNewContactForm.ShowDialog();

                    SearchContact();
                }
            }
            if (e.Button.Properties.Caption == "حذف")
            {
                if (gridView.SelectedRowsCount == 0)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("برای حذف حداقل یک آیتم را انتخاب کنید");
                    return;
                }

                System.Windows.Forms.DialogResult dialogResult =
                    DevExpress.XtraEditors.XtraMessageBox.Show("آیا از حذف آیتم های مورد نظر اطمینان دارید؟",
                                                               caption: "اخطار",
                                                               buttons: System.Windows.Forms.MessageBoxButtons.YesNo,
                                                               icon: System.Windows.Forms.MessageBoxIcon.Warning
                                                               );

                if (dialogResult == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }

                int[] selectedRows = gridView.GetSelectedRows();

                Models.Contact selectedContact =
                    gridView.GetRow(selectedRows[0]) as Models.Contact;

                if (selectedContact != null)
                {
                    Models.DatabaseContext databaseContext = null;
                    try
                    {
                        databaseContext = new Models.DatabaseContext();
                        Models.Contact contact = databaseContext.Contacts
                                                 .Where(current => current.Id == selectedContact.Id)
                                                 .FirstOrDefault();

                        databaseContext.Contacts.Remove(contact);

                        databaseContext.SaveChanges();

                        SearchContact();
                    }
                    catch (System.Exception ex)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message.ToString());
                    }
                    finally
                    {
                        if (databaseContext != null)
                        {
                            databaseContext.Dispose();
                            databaseContext = null;
                        }
                    }
                }
            }
        }
Пример #18
0
 private void addContactInternal(Contact c)
 {
     contactList.Add(c);
 }
Пример #19
0
 private async Task SignInAsync(Contact user, bool isPersistent)
 {
     AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
     var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
     AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
 }
Пример #20
0
 public void Update(Contact contact)
 {
     using (var dataContext = new ApplicationDbContext())
      {
     dataContext.Contacts.AddOrUpdate(contact);
     dataContext.SaveChanges();
      }
 }
Пример #21
0
 public ActionResult Edit(Contact contact)
 {
     db.Entry(contact).State = EntityState.Modified;
     db.SaveChanges();
     return RedirectToAction("Index");
 }
Пример #22
0
        private void removeValue(string key, Contact c, Dictionary<char, SearchablePhoneBook> dict)
        {
            if (!string.IsNullOrEmpty(key))
            {
                char first = char.ToLower(key[0]);

                if (dict.ContainsKey(first))
                {
                    SearchablePhoneBook spb = dict[first];
                    spb.removeContactInternal(c);
                    if (key.Length > 1)
                    {
                        string rest = key.Substring(1);
                        removeValue(rest, c, spb.searchDictionary);
                    }
                }
            }
        }
Пример #23
0
 private void removeContactInternal(Contact c)
 {
     contactList.Remove(c);
 }
Пример #24
0
        private void insertValue(string key, Contact c, Dictionary<char, SearchablePhoneBook> dict)
        {
            if (!string.IsNullOrEmpty(key))
            {
                char first = char.ToLower(key[0]);

                SearchablePhoneBook spb;
                if (!dict.ContainsKey(first))
                {
                    spb = new SearchablePhoneBook();
                    dict.Add(first, spb);
                }
                else
                {
                    spb = dict[first];
                }

                spb.addContactInternal(c);
                if (key.Length > 1)
                {
                    string rest = key.Substring(1);
                    insertValue(rest, c, spb.searchDictionary);
                }
            }
        }