Esempio n. 1
0
        public async Task <IActionResult> Create()
        {
            string currentUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var    currentUser   = await _userManager.FindByIdAsync(currentUserId);

            SendProposalViewModel model;

            if (await _userManager.IsInRoleAsync(currentUser, "employer"))
            {
                var vacancies = _context.Vacancies.Where(v =>
                                                         v.EmployerId == currentUserId);

                model = new SendProposalViewModel {
                    Vacancies = vacancies
                };
            }
            else
            {
                var summaries = _context.Summaries.Where(s =>
                                                         s.ApplicantId == currentUserId);

                model = new SendProposalViewModel {
                    Summaries = summaries
                };
            }

            return(View(model));
        }
        public async Task <JsonResult> SaveProposalInfo(SendProposalViewModel viewModel)
        {
            var postedFileWithoutExtension = Path.GetFileNameWithoutExtension(viewModel.Attachment.FileName);

            viewModel.Proposal_File = Utilities.SaveImage(Server, viewModel.Attachment, postedFileWithoutExtension, Constant.FILE_PATH_FOR_LEADS_PROPOSAL);
            tbl_crm_leads updateLead = Mapper.Map <SendProposalViewModel, tbl_crm_leads>(viewModel);

            ResponseMessage responseMessage = await leadsManager.SaveProposalInfoAsync(updateLead).ConfigureAwait(false);

            if (responseMessage.Type == Constant.RESPONSE_MESSAGE_TYPE_SUCCESS)
            {
                var root     = Server.MapPath(Constant.FILE_PATH_FOR_LEADS_PROPOSAL);
                var fileName = viewModel.Proposal_File;
                var path     = Path.Combine(root, fileName);
                path = Path.GetFullPath(path);

                var message = new MailMessage();
                message.To.Add(new MailAddress(viewModel.To));                                            // replace with valid value
                message.From    = new MailAddress(ConfigurationManager.AppSettings["CRM_EMAIL_ADDRESS"]); // replace with valid value
                message.Subject = viewModel.Subject;
                message.Body    = viewModel.Message;
                Attachment attachment = new Attachment(path, MediaTypeNames.Application.Octet);
                System.Net.Mime.ContentDisposition disposition = attachment.ContentDisposition;
                message.Attachments.Add(attachment);

                message.IsBodyHtml = true;

                using (var smtp = new SmtpClient())
                {
                    var credential = new NetworkCredential
                    {
                        UserName = ConfigurationManager.AppSettings["CRM_EMAIL_ADDRESS"],  // replace with valid value
                        Password = ConfigurationManager.AppSettings["CRM_EMAIL_PASSWORD"]  // replace with valid value
                    };
                    smtp.Credentials = credential;
                    smtp.Host        = "smtp.gmail.com";
                    smtp.Port        = 587;
                    smtp.EnableSsl   = true;
                    await smtp.SendMailAsync(message);
                }

                return(new JsonResult {
                    Data = new { status = true }
                });
            }
            else
            {
                return(new JsonResult {
                    Data = new { status = false }
                });
            }
        }
        public async Task <ActionResult> SendProposal(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                string email = await leadsManager.GetLeadEmailAsync(id).ConfigureAwait(false);

                SendProposalViewModel sendViewModel = new SendProposalViewModel();
                sendViewModel.Lead_ID = id;
                sendViewModel.To      = email;
                return(PartialView(sendViewModel));
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("Id, SenderId, RecipientId, RecordId, Message")]
                                                 Proposal proposal)
        {
            int i = 0;

            if (!int.TryParse(RouteData.Values["id"].ToString(), out i))
            {
                return(NotFound());
            }

            string currentUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            proposal.SenderId = currentUserId;

            int recordId    = int.Parse(RouteData.Values["id"].ToString());
            var currentUser = await _userManager.FindByIdAsync(currentUserId);

            SendProposalViewModel model;

            bool isEmployer = await _userManager.IsInRoleAsync(currentUser, "employer");

            if (isEmployer)
            {
                var summary = await _context.Summaries.FindAsync(recordId);

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

                proposal.RecipientId = summary.ApplicantId;
                var vacancies = _context.Vacancies.Where(v =>
                                                         v.EmployerId == currentUserId);

                model = new SendProposalViewModel {
                    Vacancies = vacancies
                };
            }
            else
            {
                var vacancy = await _context.Vacancies.FindAsync(recordId);

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

                proposal.RecipientId = vacancy.EmployerId;
                var summaries = _context.Summaries.Where(s =>
                                                         s.ApplicantId == currentUserId);
                model = new SendProposalViewModel {
                    Summaries = summaries
                };
            }

            proposal.CreateTime = DateTime.Now;

            if (ModelState.IsValid)
            {
                _context.Add(proposal);
                await _context.SaveChangesAsync();

                if (isEmployer)
                {
                    return(RedirectToAction("Details", "Summaries", new { id = recordId }));
                }

                return(RedirectToAction("Details", "Vacancies", new { id = recordId }));
            }

            model.Proposal = proposal;

            return(View(model));
        }