public ActionResult Create([Bind(Prefix = "Contact")] Contact contact, [Bind(Include = "Accounts")] List <Guid> accounts, [Bind(Include = "Users")] List <Guid> users)
        {
            if (ModelState.IsValid)
            {
                if (accounts == null && users == null)
                {
                    ModelState.AddModelError(string.Empty, "Contact must be associated with at least one account or user.");
                }
                else
                {
                    Contact newContact = new Contact();
                    newContact.Id          = Guid.NewGuid();
                    newContact.ContactType = contact.ContactType;
                    newContact.ContactData = contact.ContactData;

                    newContact.Accounts.Clear();
                    if (accounts != null)
                    {
                        newContact.Accounts = UOW.Accounts.GetSetByIds(accounts);
                    }

                    newContact.SkyberryUsers.Clear();
                    if (users != null)
                    {
                        newContact.SkyberryUsers = UOW.SkyberryUsers.GetSetByIds(users);
                    }

                    UOW.Contacts.Add(newContact);
                    UOW.Commit();
                    contact = newContact;
                }
            }
            ContactVM vm = new ContactVM
            {
                Contact  = contact,
                Accounts = UOW.Accounts.GetAll(),
                Users    = UOW.SkyberryUsers.GetAll()
            };

            return(View("Edit", vm));
        }
        // GET: Contact
        public ActionResult Index()
        {
            ContactRepository contactRepository = new ContactRepository();
            List <Contact>    contacts          = contactRepository.LoadAllContacts();
            List <ContactVM>  contactVMs        = new List <ContactVM>();

            foreach (Contact c in contacts)
            {
                ContactVM contactVM = new ContactVM();
                contactVM.Id          = c.Id;
                contactVM.Name        = c.Name;
                contactVM.Position    = c.Position;
                contactVM.PhoneNumber = c.PhoneNumber;
                contactVM.Company     = c.Company;
                contactVMs.Add(contactVM);
            }
            ContactVM model = new ContactVM();

            model.contacts = contactVMs;
            return(View(model));
        }
Esempio n. 3
0
        public async Task <ActionResult> Create(ContactVM vm)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    int Id = await _contactService.Add(vm);

                    if (Id > 0)
                    {
                        TempData["SuccessMessage"] = "Record Created Successfully!!!";
                        return(RedirectToAction("Index"));
                    }
                }
            }
            catch
            {
                ViewBag.ErrorMessage = "There was some error while creating the record.";
            }
            return(View(vm));
        }
Esempio n. 4
0
        /// <summary>
        /// Executing command.
        /// </summary>
        /// <param name="mainWindowVM">View-model of main window.</param>
        protected override void Execute(MainWindowVM mainWindowVM)
        {
            if (mainWindowVM.SelectedContactVM == null)
            {
                return;
            }

            var contactVM         = new ContactVM();
            var editContactWindow = new EditContactWindow {
                DataContext = contactVM
            };

            if (editContactWindow.ShowDialog() != true)
            {
                return;
            }

            mainWindowVM.ContactService.CreateContact(contactVM);
            mainWindowVM.ContactVMs.Add(contactVM);
            mainWindowVM.Update();
        }
Esempio n. 5
0
        public ActionResult Contact(ContactVM message)
        {
            var     repo           = MiscRepoFactory.CreateMiscRepo();
            Contact contactMessage = new Contact();

            if (ModelState.IsValid)
            {
                contactMessage.ContactName = message.ContactName;
                contactMessage.Email       = message.Email;
                contactMessage.Phone       = message.Phone;
                contactMessage.Message     = message.Message;

                repo.InsertMessage(contactMessage);

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(View(message));
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Create person from contact.
        /// </summary>
        /// <param name="contactVM">Contact.</param>
        public void CreateContact(ContactVM contactVM)
        {
            var newPerson = new Person();

            FillPersonData(contactVM, newPerson);

            var request = PeopleService.People.CreateContact(newPerson);

            try
            {
                var createdPerson = request.Execute();
                contactVM.ResourceName = createdPerson.ResourceName;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
                return;
            }

            GetPersons();
        }
Esempio n. 7
0
        public async Task <IActionResult> Detail(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            Data data = await _db.Data.FindAsync(id);

            if (data == null)
            {
                return(NotFound());
            }

            ContactVM contactVM = new ContactVM
            {
                Data    = data,
                Numbers = _db.CenterPhoneNumbers.Where(p => p.DataId == data.Id)
            };

            return(View(contactVM));
        }
        public async Task <IHttpActionResult> InsertContact(ContactVM xiContactVM)
        {
            IHttpActionResult response;

            if (ModelState.IsValid)
            {
                bool status = await _contactService.InsertContact(xiContactVM);

                if (status)
                {
                    return(Ok("Record inserted successfully"));
                }

                return(Content(HttpStatusCode.NotFound, "Sorry failed to insert record! Please try again or contact administrator if problem persist."));
            }

            HttpResponseMessage responseMsg = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);

            response = ResponseMessage(responseMsg);
            return(response);  // implemnted Custom Messdage with additional deatils bac.
        }
Esempio n. 9
0
        public IActionResult Put(int id, [FromBody] ContactVM contact)
        {
            var contactFound = _contactRepository.GetById(contact.Id);

            if (contactFound != null)
            {
                // Map updated details to the found contact
                contactFound.Name     = contact.Name;
                contactFound.Company  = contact.Company;
                contactFound.JobTitle = contact.JobTitle;
                contactFound.Email    = contact.Email;
                contactFound.Phone    = contact.Phone;
                contactFound.Notes    = contact.Notes;

                _contactRepository.Update();

                return(Ok());
            }

            return(NotFound());
        }
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Contact contact = UOW.Contacts.GetById(id);

            if (contact == null)
            {
                return(HttpNotFound());
            }
            ContactVM vm = new ContactVM
            {
                Contact  = contact,
                Accounts = UOW.Accounts.GetAll(),
                Users    = UOW.SkyberryUsers.GetAll()
            };

            return(View(vm));
        }
Esempio n. 11
0
        public async Task <ActionResult> Contact(ContactVM model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var body = "<p>Email From: " + "{0} ({1})</p><p>Message:" + "</p><p>{2}</p>";

                    body = string.Format(body, model.Naam, model.Email, model.Message);
                    EmailSender mail = new EmailSender();
                    await mail.ReceiveEmailAsync(model.Email, "Contact VivesTrein", body);

                    return(RedirectToAction("Sent"));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            return(View(model));
        }
Esempio n. 12
0
        public ActionResult <ResultVM <bool> > Update(ContactVM contactVM)
        {
            ResultVM <bool> resultVM = new ResultVM <bool>();

            try
            {
                ContactModel contactModel = new ContactModel();
                mapper.Map(contactVM, contactModel);
                contactModel.Services = String.Join(',', contactVM.Services);
                var result = contactBusiness.UpdateContact(contactModel);
                mapper.Map(result, resultVM);
            }
            catch (Exception ex)
            {
                Common.LogMessage(ex.Message);
                resultVM.Message    = ex.Message;
                resultVM.StatusCode = Convert.ToInt32(Enums.StatusCode.BadRequest);
                return(StatusCode(StatusCodes.Status400BadRequest, new { Result = resultVM, Codes = new string[] { "ServerError" } }));
            }
            return(resultVM);
        }
Esempio n. 13
0
        public ActionResult <ResultVM <bool> > Create(ContactVM contactVM)
        {
            ResultVM <bool> resultVM = new ResultVM <bool>();

            try
            {
                ContactModel contactModel = new ContactModel();
                mapper.Map(contactVM, contactModel);
                contactModel.Services = String.Join(',', contactVM.Services);
                //contactModel.Services = contactVM.Services.ToString();
                var result = contactBusiness.CreateContact(contactModel);
                mapper.Map(result, resultVM);
                return(resultVM);
            }
            catch (Exception ex)
            {
                resultVM.Message    = ex.Message;
                resultVM.StatusCode = Convert.ToInt32(Enums.StatusCode.BadRequest);
                return(StatusCode(StatusCodes.Status400BadRequest, new { Result = resultVM }));
            }
        }
Esempio n. 14
0
        public bool UpdateUser(ContactVM model)
        {
            try {
                if (model.Id > 0)
                {
                    var entity = _context.Entities.Single(p => p.EntityId == model.Id);
                    entity.Name        = model.Name;
                    entity.Company     = model.Company;
                    entity.Address1    = model.Address1;
                    entity.Address2    = model.Address2;
                    entity.StateId     = model.StateId;
                    entity.City        = model.City;
                    entity.Zip         = model.Zip;
                    entity.Fax         = model.Fax;
                    entity.MobilePhone = model.MobileNumber;
                    entity.OfficePhone = model.OfficeNumber;

                    var user = _context.AspNetUsers.Single(p => p.Id == model.UserId);
                    user.Email = model.Email;

                    _context.SaveChanges();
                    return(true);
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
            return(false);
        }
Esempio n. 15
0
 public ActionResult AddContact(ContactVM contactVM)
 {
     if (ModelState.IsValid)
     {
         string[]       cities    = contactVM.Address.City.Split(new char[] { ',' });
         List <Address> addresses = new List <Address>();
         foreach (var city in cities)
         {
             addresses.Add(new Address {
                 City = city
             });
         }
         contactService.AddContact(new Contact
         {
             Name         = contactVM.Contact.Name,
             MobileNumber = contactVM.Contact.MobileNumber,
             Addresses    = addresses
         });
         return(RedirectToAction("Index"));
     }
     return(View(contactVM));
 }
Esempio n. 16
0
        public async Task <IHttpActionResult> Post(ContactVM vmContact)
        {
            try
            {
                var    client      = new HttpClient();
                string url         = _ContactApiBaseUrl;
                var    content     = JsonConvert.SerializeObject(vmContact);
                var    buffer      = System.Text.Encoding.UTF8.GetBytes(content);
                var    byteContent = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var result = await client.PostAsync(url, byteContent);

                string resultContent = await result.Content.ReadAsStringAsync();

                int Id = JsonConvert.DeserializeObject <int>(resultContent);
                return(Ok(Id));
            }
            catch
            {
            }
            return(BadRequest("Some error occured while creating record"));
        }
Esempio n. 17
0
        public async Task <IActionResult> Contact(ContactVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Contact contact = new Contact()
            {
                Name         = $"{model.FirstName} {model.LastName}",
                EmailAddress = model.EmailAddress,
                Subject      = model.Subject,
                Body         = model.Body,
                Status       = ContactStatus.Pending
            };

            _dbContext.Contacts.Add(contact);
            await _dbContext.SaveChangesAsync();

            TempData["Success"] = true;
            return(RedirectToAction(nameof(Contact)));
        }
        public MessageVM UpdateContact(ContactVM contact)
        {
            var message = new MessageVM
            {
                Title       = "kontaktis shecva",
                Description = "warmatebiT sheicvala",
                Success     = true,
            };

            var Mobile  = InsertStaticData("Mobile", contact.Mobile);
            var Address = InsertStaticData("Address", contact.Address);
            var FBPage  = InsertStaticData("FBPage", contact.FBPage);
            var Email   = InsertStaticData("Email", contact.Email);

            if (!Mobile && !Address && !FBPage && !Email)
            {
                message.Description = "dafiqsirda shecdoma";
                message.Success     = false;
            }

            return(message);
        }
Esempio n. 19
0
        public void EditContact_Contact_CorrectResult()
        {
            // SetUp
            Initialize();
            var modal = this.contactManager.GetContactById(0);

            Assert.NotNull(modal);

            var newContact = new ContactVM
            {
                Id       = modal.Id,
                Name     = modal.Name,
                Surname  = "NewSurname" + Guid.NewGuid().ToString(),
                Email    = modal.Email,
                Phone    = modal.Phone,
                Vk       = modal.Vk,
                Birthday = modal.Birthday
            };

            // Act
            contactManager.EditContact(newContact);
        }
Esempio n. 20
0
        public async Task <IActionResult> Contact(ContactVM contactVM)
        {
            var emailInfo = _context.Emailnfos.First();

            MailMessage mailMessage = new MailMessage();

            mailMessage.From = new MailAddress(emailInfo.Email, "TransportMix.az");
            mailMessage.To.Add(new MailAddress(emailInfo.Email));
            mailMessage.Subject    = contactVM.Subject;
            mailMessage.IsBodyHtml = true;
            mailMessage.Body       = "Name: " + contactVM.Name + "; Email: " + contactVM.Email + "; Messages: " + contactVM.Content;

            SmtpClient smtpClient = new SmtpClient("smtp.gmail.com");

            smtpClient.Port = 587;
            smtpClient.UseDefaultCredentials = false;
            smtpClient.EnableSsl             = true;
            smtpClient.Credentials           = new NetworkCredential(emailInfo.Email, emailInfo.Password);
            smtpClient.DeliveryMethod        = SmtpDeliveryMethod.Network;
            await smtpClient.SendMailAsync(mailMessage);

            return(RedirectToAction("Contact"));
        }
Esempio n. 21
0
        // GET: ContactClient/Details/5
        public async Task <ActionResult> Details(int id)
        {
            ContactVM vm = new ContactVM();

            try
            {
                var    client = new HttpClient();
                string url    = _ContactApiBaseUrl + id;
                var    result = await client.GetAsync(url);

                string resultContent = await result.Content.ReadAsStringAsync();

                vm = JsonConvert.DeserializeObject <ContactVM>(resultContent);
                if (vm != null)
                {
                    return(View(vm));
                }
            }
            catch
            {
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 22
0
        public static Contact MapToContact(ContactVM contact)
        {
            Contact result = new MapperConfiguration(cfg => cfg.CreateMap <ContactVM, Contact>()
                                                     .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
                                                     .ForMember(dest => dest.FirstName, opt => opt.MapFrom(src => src.FirstName))
                                                     .ForMember(dest => dest.LastName, opt => opt.MapFrom(src => src.LastName))
                                                     .ForMember(dest => dest.Patronymic, opt => opt.MapFrom(src => src.Patronymic))
                                                     .ForMember(dest => dest.Email, opt => opt.MapFrom(src => src.Email))
                                                     .ForMember(dest => dest.PhoneNumber, opt => opt.Ignore())
                                                     .ForMember(dest => dest.Note, opt => opt.Ignore())
                                                     //.ForMember(dest => dest.PhoneNumber, opt => opt.MapFrom(src => string.IsNullOrEmpty(src.Number)
                                                     //        ? src.Number.Aggregate((i, j) => new List<PhoneNumber> { new PhoneNumber { Number = (i.Number + "; " + j.Number) } }).Number
                                                     //        : "-"))

                                                     //.ForMember(dest => dest.Note, opt => opt.MapFrom(src => src.Note.Count > 0
                                                     //        ? src.Note.Aggregate((i, j) => new Note { NoteText = (i.NoteText + "; " + j.NoteText) }).NoteText
                                                     //        : "-"))
                                                     ).CreateMapper().Map <ContactVM, Contact>(contact);

            //result.PhoneNumber = new List<PhoneNumber>() { new PhoneNumber { Number = contact.Number } };
            //result.Note = new List<Note>() { new Note { NoteText = contact.Note } };
            return(result);
        }
        public async Task <ContactVM> GetContactById(int xiContactId)
        {
            try
            {
                var objContact = (await _repo.FindAsync <Contact>(_ => _.Id.Equals(xiContactId)));

                ContactVM objContactVM = new ContactVM
                {
                    Id          = objContact.Id,
                    FirstName   = objContact.FirstName,
                    LastName    = objContact.LastName,
                    Email       = objContact.Email,
                    PhoneNumber = objContact.PhoneNumber,
                    StatusID    = objContact.StatusID
                };

                return(objContactVM);
            }
            catch (Exception ex)
            {
                throw ex;//Write exception Logger or Handle with GlobalErrorHandler Filter
            }
        }
Esempio n. 24
0
        public async Task <IHttpActionResult> Get(int id)
        {
            ContactVM vm = new ContactVM();

            try
            {
                var    client = new HttpClient();
                string url    = _ContactApiBaseUrl + id;
                var    result = await client.GetAsync(url);

                string resultContent = await result.Content.ReadAsStringAsync();

                vm = JsonConvert.DeserializeObject <ContactVM>(resultContent);
                if (vm != null)
                {
                    return(Ok(vm));
                }
            }
            catch
            {
            }
            return(NotFound());
        }
Esempio n. 25
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            Data data = await _db.Data.FindAsync(id);

            if (data == null)
            {
                return(NotFound());
            }
            TempData["Numbers"] = "";

            ContactVM contactVM = new ContactVM
            {
                Data       = data,
                Numbers    = _db.CenterPhoneNumbers.Where(p => p.DataId == data.Id),
                AllNumbers = _db.CenterPhoneNumbers.ToList()
            };

            return(View(contactVM));
        }
Esempio n. 26
0
        // GET: Contact/Delete/5
        public async Task <ActionResult> Delete(int id)
        {
            if (TempData["ErrorMessage"] != null)
            {
                ViewBag.ErrorMessage = TempData["ErrorMessage"].ToString();
            }

            ContactVM vm = new ContactVM();

            try
            {
                vm = await _contactService.Get(id);

                if (vm != null)
                {
                    return(View(vm));
                }
            }
            catch
            {
            }
            TempData["ErrorMessage"] = "No Record Found!!!";
            return(RedirectToAction("Index"));
        }
Esempio n. 27
0
        public void EditContact_NonExistentContact_ThrowException()
        {
            // SetUp
            Initialize();
            var newContact = new ContactVM
            {
                Id       = 100,
                Name     = Guid.NewGuid().ToString(),
                Surname  = "NewSurname" + Guid.NewGuid().ToString(),
                Email    = "*****@*****.**",
                Phone    = "89999999999",
                Vk       = "test",
                Birthday = DateTime.Now.Date,
            };

            // Assert
            var ex = Assert.Throws <ArgumentException>(() =>
            {
                // Act
                contactManager.EditContact(newContact);
            });

            Assert.AreEqual("Contact not found", ex.Message);
        }
Esempio n. 28
0
        public ActionResult UpdateUser(ContactVM model)
        {
            if (ModelState.IsValid)
            {
                if (model.MobileNumber != null)
                {
                    model.MobileNumber = model.MobileNumber.Replace("(", "").Replace(")", "").Replace("-", "").Replace(" ", "");
                }
                if (model.OfficeNumber != null)
                {
                    model.OfficeNumber = model.OfficeNumber.Replace("(", "").Replace(")", "").Replace("-", "").Replace(" ", "");
                }
                if (model.Fax != null)
                {
                    model.Fax = model.Fax.Replace("(", "").Replace(")", "").Replace("-", "").Replace(" ", "");
                }

                var result = _userService.UpdateUser(model);
                TempData["SuccessMessage"] = "Contact information updated successfully.";
                return(RedirectToAction("Index", "Manage"));
            }
            TempData["ErrorMessage"] = "User not updated.";
            return(RedirectToAction("Index", "Manage"));
        }
Esempio n. 29
0
        public ActionResult UserContact(ContactVM model)
        {
            //Hata mesajları yazılır. Viewbag işlem durumları
            if (ModelState.IsValid)
            {
                for (int i = 0; i < 100; i++)
                {
                    Contact contact = new Contact();
                    contact.EMail   = model.EMail;
                    contact.Phone   = model.Phone;
                    contact.Message = model.Message;
                    contact.Name    = model.Name;

                    db.Contacts.Add(contact);
                    db.SaveChanges();
                }

                return(View());
            }
            else
            {
                return(View());
            }
        }
Esempio n. 30
0
        public ActionResult Contact(ContactVM contactVM)
        {
            if (String.IsNullOrWhiteSpace(contactVM.Email) && String.IsNullOrWhiteSpace(contactVM.Phone))
            {
                ModelState.AddModelError("m.Email", "Must Provide Either Email or Phone");
            }

            if (ModelState.IsValid)
            {
                var customer = new Customer();
                var contact  = new Contact();

                customer.FirstName = contactVM.FirstName;
                customer.LastName  = contactVM.LastName;

                if (!String.IsNullOrWhiteSpace(contactVM.Email))
                {
                    customer.Email = contactVM.Email;
                }

                if (!String.IsNullOrWhiteSpace(contactVM.Phone))
                {
                    customer.Phone = contactVM.Phone;
                }

                contact.Message = contactVM.Message;

                var repo = ContactsRepositoryFactory.GetRepository();

                repo.Insert(customer, contact);

                return(RedirectToAction("Contact", new { id = "submitted" }));
            }

            return(View("Contact", contactVM));
        }