示例#1
0
        public async Task <ActionResult> CreateAsync(ContactPersonViewModel person)
        {
            if (!ModelState.IsValid)
            {
                return(View(person));
            }

            var sessionId         = HttpContext.GetSessionId();
            var resumeAttachments =
                await _resumeManager.GetFilesAsync(sessionId, MimeTypeId.Pdf).ConfigureAwait(false);

            var codeExamplesAttachments =
                await _resumeManager.GetFilesAsync(sessionId, MimeTypeId.Zip).ConfigureAwait(false);

            // TOREFACTOR: Отправка почты - довольно долгая операция, которая может привести к таймауту (с дальнейшей отменой операции):
            // стоит предусмотреть очередь на отправку, вместо фактического ожидания
            var contactUsResult =
                await
                _contactSender.ContactUsAsync(
                    person, resumeAttachments, codeExamplesAttachments, _credentials, _recipients).ConfigureAwait(false);

            if (contactUsResult)
            {
                /*var deletedCount = */ await _resumeManager.DeleteAsync(sessionId).ConfigureAwait(false);

                TempData[TempDataContants.NotificationKey] = Resources.ContactUsController_SuccessfullySent;
                return(RedirectToAction("Index", "Home"));
            }

            ModelState.AddModelError(string.Empty, Resources.ContactUsController_ErrorSendingEmail);

            return(View(person));
        }
        public ActionResult Edit(int id)
        {
            ContactPersonViewModel vm = new ContactPersonViewModel();

            vm.Id = id;

            try
            {
                DataRow dr = (from d in model.GetContactPerson(id).Table.AsEnumerable()
                              select d).First();

                vm.Cid         = int.Parse(dr[tblDef.Cid.Name].ToString());
                vm.Forename    = dr[tblDef.Forename.Name].ToString();
                vm.Surname     = dr[tblDef.Surname.Name].ToString();
                vm.Gender      = dr[tblDef.Gender.Name].ToString();
                vm.Email       = dr[tblDef.Email.Name].ToString();
                vm.Phone       = dr[tblDef.Phone.Name].ToString();
                vm.MainContact = (bool)dr[tblDef.MainContact.Name];
            }
            catch (Exception e)
            {
                ModelState.AddModelError("noData", e);
            }

            return(View("FrmContactPerson", vm));
        }
        //[AuthorizeUser(RoleModule.ContactPerson, Function.View)]
        public JsonResult GetContactPersonList(ContactPersonViewModel vViewModel)
        {
            PaginationInfo pager = new PaginationInfo();

            pager = vViewModel.Pager;

            PaginationViewModel pViewModel = new PaginationViewModel();

            try
            {
                //vViewModel.Contact.ContactFor = ContactFor.Company.ToString();

                pViewModel.dt = _ContactPersonManager.Get_Contact_By_Type_For(vViewModel.ContactPersonDetails, ref pager);

                pViewModel.Pager = pager;

                Logger.Debug("Contact Person Controller GetContactList");
            }

            catch (Exception ex)
            {
                vViewModel.FriendlyMessage.Add(MessageStore.Get("SYS01"));

                Logger.Error("Contact Person Controller - GetContactList" + ex.ToString());
            }

            return(Json(JsonConvert.SerializeObject(pViewModel), JsonRequestBehavior.AllowGet));
        }
        //[AuthorizeUser(RoleModule.ContactPerson, Function.Create)]
        public JsonResult InsertContactPerson(ContactPersonViewModel cViewModel)
        {
            Set_Date_Session(cViewModel.ContactPersonDetails);

            using (TransactionScope tran = new TransactionScope())
            {
                try
                {
                    cViewModel.ContactPersonDetails.ContactPersonId = _ContactPersonManager.Insert_ContactPerson(cViewModel.ContactPersonDetails);
                    //cViewModel.ContactPersonViewModelList.Contact.ContactFor = ContactFor.Contact.ToString();

                    cViewModel.FriendlyMessage.Add(MessageStore.Get("Cont01"));

                    Logger.Debug("Contact Person Controller Insert Contact");

                    tran.Complete();
                }
                catch (Exception ex)
                {
                    tran.Dispose();

                    cViewModel.FriendlyMessage.Add(MessageStore.Get("SYS01"));

                    Logger.Error("Contact Person Controller - Insert Method : " + ex.Message);
                }
            }
            return(Json(cViewModel));
        }
示例#5
0
        public JsonResult <List <ContactPersonViewModel> > ContactPersons(int cid)
        {
            DefTblContactPersons          tblDef         = model.TblContactPersons;
            List <ContactPersonViewModel> contactPersons = new List <ContactPersonViewModel>();
            ContactPersonViewModel        cp;

            model.LoadContactPersons(cid);

            foreach (DataRow dr in model.ContactPersons.Table.AsEnumerable())
            {
                cp = new ContactPersonViewModel();

                cp.Id          = int.Parse(dr[tblDef.Id.Name].ToString());
                cp.Cid         = int.Parse(dr[tblDef.Cid.Name].ToString());
                cp.Forename    = dr[tblDef.Forename.Name].ToString();
                cp.Surname     = dr[tblDef.Surname.Name].ToString();
                cp.Gender      = dr[tblDef.Gender.Name].ToString();
                cp.Email       = dr[tblDef.Email.Name].ToString();
                cp.Phone       = dr[tblDef.Phone.Name].ToString();
                cp.MainContact = (bool)dr[tblDef.MainContact.Name];

                contactPersons.Add(cp);
            }

            return(Json(contactPersons));
        }
        public void SubmitContactPerson()
        {
            // ---- Arrange ----
            // set up model
            DefTblContactPersons def = new DefTblContactPersons();

            CRM_web.Models.Model.Model m = CRM_web.Models.Model.Model.GetModel();
            TestCase.CleanUp();
            m.ExecuteActionQuery(String.Format("DELETE FROM {0} WHERE {1} = {2};", def.TblName, def.Cid.Name, TestContactPerson.cid));
            TestCase.PopulateTestData();
            m.Cid = TestContactPerson.cid;
            m.LoadCustomers();
            m.LoadContactPersons(TestCustomer.cid);
            //Thread.Sleep(1000);
            // set up controller and view model
            FrmContactPersonController controller = new FrmContactPersonController();
            ContactPersonViewModel     vm         = new ContactPersonViewModel();

            vm.Id          = TestContactPerson.id;
            vm.Cid         = TestContactPerson.cid;
            vm.Forename    = TestContactPerson.forename;
            vm.Surname     = TestContactPerson.surname;
            vm.Gender      = TestContactPerson.gender;
            vm.Email       = TestContactPerson.email;
            vm.Phone       = TestContactPerson.phone;
            vm.MainContact = TestContactPerson.mainContact;

            // ---- Act ----
            RedirectToRouteResult result = controller.Submit(vm) as RedirectToRouteResult;

            Thread.Sleep(1000);
            m.LoadContactPersons(TestCustomer.cid);
            Thread.Sleep(1000);

            // ---- Assert ----
            Assert.IsNotNull(result);
            // check new entries in database
            int lastEntry = 0;
            int max       = 0;

            for (int i = 0; i < m.ContactPersons.Count; i++)
            {
                if (int.Parse(m.ContactPersons[i][def.Id.Name].ToString()) > max)
                {
                    max       = int.Parse(m.ContactPersons[i][def.Id.Name].ToString());
                    lastEntry = i;
                }
            }
            Assert.AreEqual(m.ContactPersons[lastEntry][def.Cid.Name], TestContactPerson.cid);
            Assert.AreEqual(m.ContactPersons[lastEntry][def.Forename.Name], TestContactPerson.forename);
            Assert.AreEqual(m.ContactPersons[lastEntry][def.Surname.Name], TestContactPerson.surname);
            Assert.AreEqual(m.ContactPersons[lastEntry][def.Gender.Name], TestContactPerson.gender);
            Assert.AreEqual(m.ContactPersons[lastEntry][def.Email.Name], TestContactPerson.email);
            Assert.AreEqual(m.ContactPersons[lastEntry][def.Phone.Name], TestContactPerson.phone);
            Assert.AreEqual(m.ContactPersons[lastEntry][def.MainContact.Name], TestContactPerson.mainContact);

            // clean up model
            m.ExecuteActionQuery(String.Format("DELETE FROM {0} WHERE {1} = {2};", def.TblName, def.Cid.Name, TestContactPerson.cid));
            TestCase.CleanUp();
        }
示例#7
0
        public async Task <IActionResult> GetContactPerson(ContactPersonViewModel personViewModel, DataTablesRequest dtReq)
        {
            var personList = await ContPersonService.FindPerson(personViewModel, dtReq);

            var personVM = Mapper.Map <IEnumerable <ContactPersonCreateViewModel> >(personList.Items);

            return(Json(new DataTablesResponse(dtReq.draw, personVM, personList.TotalCount, personList.TotalCount).ToJson()));
        }
        // GET: FrmContactPerson
        public ActionResult New(int cid)
        {
            ContactPersonViewModel vm = new ContactPersonViewModel();

            vm.Id  = 0;
            vm.Cid = cid;
            return(View("FrmContactPerson", vm));
        }
        /// <summary>
        ///    Send information about contact
        /// </summary>
        /// <param name="aPerson">A person who contacts</param>
        /// <param name="resumeFiles">Resume files</param>
        /// <param name="codeExampleFiles">Code example files</param>
        /// <param name="credentials">Credentials</param>
        /// <param name="recipients">Recipient collection</param>
        /// <returns>true, if successfully sending contact information, false otherwise</returns>
        public async Task <bool> ContactUsAsync(ContactPersonViewModel aPerson,
                                                IEnumerable <UploadedFileInfo> resumeFiles,
                                                IEnumerable <UploadedFileInfo> codeExampleFiles,
                                                ICredentials credentials,
                                                IRecipientCollection recipients)
        {
            var smtpClient = new SmtpClient(credentials.SmtpServerName, credentials.SmtpPort)
            {
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(credentials.MailLogin, credentials.MailPassword)
            };

            string messageBody     = aPerson.GenerateMessageBody();
            var    fromAddr        = new MailAddress(credentials.FromAddress, credentials.FromDisplayName, _DefaultEncoding);
            var    emailRecipients = recipients.Recipients;
            var    mailAddresses   =
                emailRecipients.Select(
                    recipient => new MailAddress(recipient.ToAddress, recipient.ToDisplayName, _DefaultEncoding)).ToList();

            foreach (MailAddress toAddr in mailAddresses)
            {
                using (var message = new MailMessage(fromAddr, toAddr)
                {
                    Subject = string.Format("Resume: {0} {1}", aPerson.FirstName, aPerson.LastName),
                    Body = messageBody,
                    DeliveryNotificationOptions = DeliveryNotificationOptions.None,
                    SubjectEncoding = _DefaultEncoding
                })
                {
                    foreach (Attachment attachment in GenerateAttachments(resumeFiles, codeExampleFiles))
                    {
                        message.Attachments.Add(attachment);
                    }

                    try
                    {
                        await smtpClient.SendMailAsync(message).ConfigureAwait(false);
                    }
                    catch (InvalidOperationException invalidOperationEx)
                    {
                        throw new SendingMailException(Resources.ErrorSendingEmail, invalidOperationEx);
                    }
                    catch (SmtpFailedRecipientException smtpFailedRecipientEx)
                    {
                        throw new SendingMailException(Resources.ErrorSendingEmail, smtpFailedRecipientEx);
                    }
                    catch (SmtpException smtpEx)
                    {
                        throw new SendingMailException(Resources.ErrorSendingEmail, smtpEx);
                    }
                }
            }

            return(true);
        }
示例#10
0
        public IActionResult Contact()
        {
            var viewModel = new ContactPersonViewModel()
            {
                Name            = "William Cheng",
                CellPhoneNumber = "0923-9XX-X1X",
                Address         = "高雄市三民區七賢十路577號105樓"
            };

            return(View(viewModel));
        }
        public ActionResult Submit(ContactPersonViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(View("FrmContactPerson", vm));
            }

            EntryMode em = vm.Id == 0 ? EntryMode.New : EntryMode.Edit;

            model.Submit(vm.getMap(), model.TblContactPersons.TblName, new Tuple <ColDef, object>(model.TblContactPersons.Id, vm.Id), em);

            return(RedirectToAction("Search", "Cockpit", new { cid = vm.Cid.ToString() }));
        }
        public void NewContactPerson()
        {
            // Arrange
            FrmContactPersonController controller = new FrmContactPersonController();

            // Act
            ViewResult result = controller.New(TestCustomer.cid) as ViewResult;

            // Assert
            ContactPersonViewModel vm = result.Model as ContactPersonViewModel;

            Assert.AreEqual(0, vm.Id);
            Assert.AreEqual(TestCustomer.cid, vm.Cid);
        }
        /// <summary>
        ///    Generate the message body pattern
        /// </summary>
        /// <param name="person">Person</param>
        /// <returns>Message body pattern</returns>
        public static string GenerateMessageBody(this ContactPersonViewModel person)
        {
            var body = new StringBuilder();

            body.AppendLine(string.Format("First name - {0}", person.FirstName))
            .AppendLine(string.Format("Last name - {0}", person.LastName))
            .AppendLine(string.Format("Telephone number - {0}", person.TelephoneNumber))
            .AppendLine(string.Format("Email - {0}", person.Email))
            .AppendLine(string.Format("Birth date - {0:dd.mm.yyyy}", person.BirthDate))
            .AppendLine(string.Format("C/C++ level - {0}", person.CAndCppKnowledge.GetPercentStr()))
            .AppendLine(string.Format("C# level - {0}", person.CSharpKnowledge.GetPercentStr()))
            .AppendLine(string.Format("OOD level - {0}", person.OodKnowledge.GetPercentStr()))
            .AppendLine(string.Format("OOP level - {0}", person.OopKnowledge.GetPercentStr()))
            .AppendLine(string.Format("Refactoring - {0}", person.RefactoringKnowledge.GetPercentStr()))
            .AppendLine(string.Format("English level - {0}", person.Language))
            .AppendLine(string.Format("Summary information - {0}", person.SummaryInfo));

            return(body.ToString());
        }
        //[AuthorizeUser(RoleModule.ContactPerson, Function.View)]
        public JsonResult GetContactPersonById(ContactPersonViewModel vViewModel)
        {
            try
            {
                vViewModel.ContactPersonDetails = _ContactPersonManager.Get_ContactPerson_By_Id(vViewModel.ContactPersonDetails.ContactPersonId);

                Logger.Debug("Contact Person Controller GetContactById");
            }
            catch (Exception ex)
            {
                vViewModel.FriendlyMessage.Add(MessageStore.Get("SYS01"));

                Logger.Error("Contact Person Controller - GetContactById" + ex.ToString());
            }

            TempData["vViewModel"] = vViewModel;


            return(Json(vViewModel, JsonRequestBehavior.AllowGet));
        }
示例#15
0
 public ActionResult ContactPersonSave(ContactPersonViewModel cpVM)
 {
     if (ModelState.IsValid)
     {
         Person        p  = Session["Person"] as Person;
         ContactPerson cp = hrServices.CreateContactPerson(cpVM, p);
         if (cp != null)
         {
             return(RedirectToAction("DisplaySuccessOfAddWorker"));
         }
         else
         {
             ModelState.AddModelError("", "Nieznany blad");
             return(View("AddEmploymentInformation", cpVM));
         }
     }
     else
     {
         return(View("AddEmploymentInformation", cpVM));
     }
 }
        public void GetContactPersons()
        {
            // Arrange
            TestCase.PopulateTestData();
            WebServiceController controller = new WebServiceController();

            // Act
            JsonResult <List <ContactPersonViewModel> > result = controller.ContactPersons(TestCustomer.cid) as JsonResult <List <ContactPersonViewModel> >;

            // Assert
            ContactPersonViewModel cp = result.Content.Find(c => c.Id == TestContactPerson.id);

            Assert.AreEqual(TestContactPerson.id, cp.Id);
            Assert.AreEqual(TestContactPerson.cid, cp.Cid);
            Assert.AreEqual(TestContactPerson.forename, cp.Forename);
            Assert.AreEqual(TestContactPerson.surname, cp.Surname);
            Assert.AreEqual(TestContactPerson.gender, cp.Gender);
            Assert.AreEqual(TestContactPerson.email, cp.Email);
            Assert.AreEqual(TestContactPerson.phone, cp.Phone);
            Assert.AreEqual(TestContactPerson.mainContact, cp.MainContact);

            TestCase.CleanUp();
        }
示例#17
0
        public ContactPerson CreateContactPerson(ContactPersonViewModel cpVM, Person p)
        {
            try
            {
                employmentUnityOfWork.PersonRepo.Attach(ref p);

                ContactPerson c = new ContactPerson
                {
                    ApartmentNumber = cpVM.ApartmentNumber,
                    BuildingNumber  = cpVM.BuildingNumber,
                    City            = cpVM.City,
                    Email           = cpVM.Email,
                    FirstName       = cpVM.FirstName,
                    Phone           = cpVM.Phone,
                    PostalCode      = cpVM.PostalCode,
                    Street          = cpVM.Street,
                    Surname         = cpVM.Surname,
                    Person          = p
                };

                p.ContactPerson = c;
                employmentUnityOfWork.ContactPersonRepo.Add(c);
                employmentUnityOfWork.PersonRepo.Update(p);
                employmentUnityOfWork.UnityOfWork.SaveChanges();


                return(c);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                employmentUnityOfWork.UnityOfWork.Dispose();
            }
        }
        public void EditContactPerson()
        {
            // Arrange
            TestCase.PopulateTestData();
            FrmContactPersonController controller = new FrmContactPersonController();

            // Act
            ViewResult result = controller.Edit(TestContactPerson.id) as ViewResult;

            // Assert
            ContactPersonViewModel vm = result.Model as ContactPersonViewModel;

            Assert.AreEqual(TestContactPerson.id, vm.Id);
            Assert.AreEqual(TestContactPerson.cid, vm.Cid);
            Assert.AreEqual(TestContactPerson.forename, vm.Forename);
            Assert.AreEqual(TestContactPerson.surname, vm.Surname);
            Assert.AreEqual(TestContactPerson.gender, vm.Gender);
            Assert.AreEqual(TestContactPerson.email, vm.Email);
            Assert.AreEqual(TestContactPerson.phone, vm.Phone);
            Assert.AreEqual(TestContactPerson.mainContact, vm.MainContact);

            // clean up
            TestCase.CleanUp();
        }
        public async Task<ActionResult> MainContactPerson(ContactPersonViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                using (var client = apiClient())
                {
                    try
                    {
                        await client.SendAsync(User.GetAccessToken(), viewModel.ToAddRequest());
                        return RedirectToAction("OrganisationAddress", new
                        {
                            viewModel.OrganisationId
                        });
                    }
                    catch (ApiBadRequestException ex)
                    {
                        this.HandleBadRequest(ex);

                        if (ModelState.IsValid)
                        {
                            throw;
                        }
                    }
                    catch (ApiException ex)
                    {
                        if (ex.ErrorData != null)
                        {
                            ModelState.AddModelError("Unable to save the address.", ex.Message);
                            return View(viewModel);
                        }
                    }

                    return View(viewModel);
                }
            }
            return View(viewModel);
        }
        public async Task<ActionResult> MainContactPerson(Guid organisationId)
        {
            using (var client = apiClient())
            {
                /* RP: Check with the API to see if this is a valid organisation
                 * It would be annoying for a user to fill out a form only to get an error at the end, 
                 * when this could be avoided by checking the validity of the ID before the page loads */
                var organisationExists = await client.SendAsync(User.GetAccessToken(), new VerifyOrganisationExists(organisationId));

                if (!organisationExists)
                {
                    throw new ArgumentException("No organisation found for supplied organisation Id", "organisationId");
                }

                ContactPersonViewModel model;
                var contactPerson = await client.SendAsync(User.GetAccessToken(), new GetContactPersonByOrganisationId(organisationId));
                if (contactPerson.HasContact)
                {
                    model = new ContactPersonViewModel(contactPerson);
                }
                else
                {
                    model = new ContactPersonViewModel { OrganisationId = organisationId };
                }

                return View(model);
            }
        }
示例#21
0
 public async Task <IPagedList <MS_PIC> > FindPerson(ContactPersonViewModel search, DataTablesRequest dtReq)
 {
     return(await Repo.GetContactList(contactName : search.ContactName, vendorCode : search.VendorCode,
                                      department : search.DepartmentName,
                                      pageIndex : dtReq.pageIndex, pageSize : dtReq.pageSize));
 }
 public ContactPersonView()
 {
     InitializeComponent();
     DataContext = new ContactPersonViewModel();
 }
示例#23
0
        private DeliveryViewModel MapToDeliveryViewModel(dynamic queryResult)
        {
            var pickUpContactPerson = new ContactPersonViewModel
            {
                Name  = queryResult.PickUpLocation_ContactPerson_Name,
                Phone = queryResult.PickUpLocation_ContactPerson_Phone
            };

            var pickUpDeliveryLocation = new DeliveryLocationViewModel
            {
                Address                = queryResult.PickUpLocation_Address,
                BuildingNumber         = queryResult.PickUpLocation_BuildingNumber,
                EntranceNumber         = queryResult.PickUpLocation_EntranceNumber,
                FloorNumber            = queryResult.PickUpLocation_FloorNumber,
                ApartmentNumber        = queryResult.PickUpLocation_ApartmentNumber,
                Latitude               = queryResult.PickUpLocation_Latitude,
                Longitude              = queryResult.PickUpLocation_Longitude,
                Note                   = queryResult.PickUpLocation_Note,
                ContactPerson          = pickUpContactPerson,
                ArrivalStartDateTime   = queryResult.PickUpLocation_ArrivalStartDateTime,
                ArrivalFinishDateTime  = queryResult.PickUpLocation_ArrivalFinishDateTime,
                CourierArrivedDateTime = queryResult.PickUpLocation_CourierArrivedDateTime
            };

            var dropOffContactPerson = new ContactPersonViewModel
            {
                Name  = queryResult.DropOffLocation_ContactPerson_Name,
                Phone = queryResult.DropOffLocation_ContactPerson_Phone
            };

            var dropOffDeliveryLocation = new DeliveryLocationViewModel
            {
                Address                = queryResult.DropOffLocation_Address,
                BuildingNumber         = queryResult.DropOffLocation_BuildingNumber,
                EntranceNumber         = queryResult.DropOffLocation_EntranceNumber,
                FloorNumber            = queryResult.DropOffLocation_FloorNumber,
                ApartmentNumber        = queryResult.DropOffLocation_ApartmentNumber,
                Latitude               = queryResult.DropOffLocation_Latitude,
                Longitude              = queryResult.DropOffLocation_Longitude,
                Note                   = queryResult.DropOffLocation_Note,
                ContactPerson          = dropOffContactPerson,
                ArrivalStartDateTime   = queryResult.DropOffLocation_ArrivalStartDateTime,
                ArrivalFinishDateTime  = queryResult.DropOffLocation_ArrivalFinishDateTime,
                CourierArrivedDateTime = queryResult.DropOffLocation_CourierArrivedDateTime
            };

            var delivery = new DeliveryViewModel
            {
                Id               = queryResult.Id,
                Number           = queryResult.Number,
                CreatedDateTime  = queryResult.CreatedDateTime,
                FinishedDateTime = queryResult.FinishedDateTime,
                Price            = queryResult.Price,
                Weight           = queryResult.Weight,
                Note             = queryResult.Note,
                PickUpLocation   = pickUpDeliveryLocation,
                DropOffLocation  = dropOffDeliveryLocation,
                DeliveryStatus   = queryResult.DeliveryStatus,
                ClientId         = queryResult.ClientId,
                CourierId        = queryResult.CourierId
            };

            return(delivery);
        }