Пример #1
0
    void LoadIntervieweLocation()
    {
        //bind repeater
        var list = new Interviews().GetInterviewLocations().ToList();

        if (list.Count > 0)
        {
            rptInterviewLocation.DataSource = list;
            rptInterviewLocation.DataBind();
            items.Visible = true;
        }
        else
            items.Visible = false;

    }
    void Save()
    {
        int locationId = new Interviews().AddUpdateInterviewLocation(new InterviewLocation()
          {
              Id = int.Parse(lblLocationId.Text),
              Location = txtTitle.Text,
              LocationAddress = txtAddress.Text,
              Postcode = txtPostcode.Text,
              Directions = txtDirections.Text,
              CoX = (txtLat.Text != "" && txtLat.Text.IsFloat() && float.Parse(txtLat.Text) != 0) ? float.Parse(txtLat.Text) : 0,
              CoY = (txtLng.Text != "" && txtLng.Text.IsFloat() && float.Parse(txtLng.Text) != 0) ? float.Parse(txtLng.Text) : 0,
          });

        //load location
        LoadLocation(locationId);

    }
    void Save()
    {
        int interviewerId = new Interviews().AddUpdateInterviewers(new Interviewer()
          {
              Id = int.Parse(lblInterviewrId.Text),
              Forename = txtForename.Text,
              Surname = txtSurname.Text,
              JobTitle = txtJobTitle.Text,
              Company = txtCompany.Text,
              Email = txtEmail.Text,
              Telephone = txtTelephone.Text
          });

        //load
        LoadInterviewer(interviewerId);

    }
    void LoadInterviewer(int interviewerId)
    {
        Interviewer interviewer = new Interviews().GetInterviewer(interviewerId);

        if (interviewer != null)
        {
            lblInterviewrId.Text = interviewer.Id.ToString();
            txtForename.Text = interviewer.Forename;
            txtSurname.Text = interviewer.Surname;
            txtJobTitle.Text = interviewer.JobTitle;
            txtCompany.Text = interviewer.Company;
            txtEmail.Text = interviewer.Email;
            txtTelephone.Text = interviewer.Telephone;
        }
        else
        {
            Response.Redirect("/404.aspx");
        }

    }
    void LoadLocation(int locationId)
    {
        InterviewLocation loc = new Interviews().GetInterviewLocation(locationId);

        if (loc != null)
        {
            lblLocationId.Text = loc.Id.ToString();
            txtTitle.Text = loc.Location;
            txtAddress.Text = loc.LocationAddress;
            txtPostcode.Text = loc.Postcode;
            txtDirections.Text = loc.Directions;

            if (loc.CoX != 0) txtLat.Text = loc.CoX.ToString();
            if (loc.CoY != 0) txtLng.Text = loc.CoY.ToString();
        }
        else
        {
            Response.Redirect("/404.aspx");
        }

    }
Пример #6
0
        /// <summary>
        /// Do not replace the body if the object is null
        /// </summary>
        /// <param name="rawBody"></param>
        /// <param name="contactId"></param>
        /// <param name="jobId"></param>
        /// <param name="userId"></param>
        /// <param name="consultantid"></param>
        /// <param name="clientId"></param>
        /// <param name="candidate"></param>
        /// <param name="job"></param>
        /// <param name="cUser"></param>
        /// <param name="consultant"></param>
        /// <param name="client"></param>
        /// <param name="intRequestId"></param>
        /// <param name="timeSlotId"></param>
        /// <returns></returns>
        public string GetOriginalBodyForPreview(string rawBody, int contactId = 0, int jobId = 0, int userId = 0, int consultantid = 0, int clientId = 0,
        Candidate candidate = null, Job job = null, User cUser = null, User consultant = null, Client client = null, int intRequestId = 0, int timeSlotId = 0)
        {
            // get contact by id  
            if (contactId > 0)
                candidate = new Contacts().GetCandidate(contactId);
            //retrieve objects if null and have an id passed
            if (job == null && jobId > 0)
                job = new Jobs().GetJob(jobId);
            if (cUser == null && userId > 0)
                cUser = new Users().GetUser(userId);
            if (consultant == null && consultantid > 0)
                consultant = new Users().GetUser(consultantid);
            if (client == null && clientId > 0)
                client = new Clients().GetClient(clientId);

            InterviewRequest intRequest = null;
            if (intRequestId > 0)
            {
                intRequest = new Interviews().GetInterviewRequest(intRequestId);
            }

            TimeSlot timeSlot = null;
            if (timeSlotId > 0)
            {
                timeSlot = new Interviews().GetTimeSlot(timeSlotId);
            }

            //Contact
            if (candidate != null)
            {
                var pwdlink = "http://www.resonatesearch.co.uk/reset-password.aspx?token=" + candidate.RefId;
                rawBody = rawBody.Replace("#ContactTitle#", candidate.Title);
                rawBody = rawBody.Replace("#ContactForename#", candidate.Forename);
                rawBody = rawBody.Replace("#ContactSurname#", candidate.Surname);
                rawBody = rawBody.Replace("#ContactJobTitle#", candidate.JobTitle);
                rawBody = rawBody.Replace("#ContactEmployer#", candidate.Employer);
                rawBody = rawBody.Replace("#ContactEmail#", candidate.Email);
                rawBody = rawBody.Replace("#ContactPassword#", candidate.Password);
                if (string.IsNullOrEmpty(candidate.Password))
                    rawBody = rawBody.Replace("#PasswordResetLink#", "If you wish to create a password for your account on  Resonate Search please click link below:<br/><a href='" + pwdlink + "'>" + pwdlink + "</a><br/>");
                else
                    rawBody = rawBody.Replace("#PasswordResetLink#", "");
            }


            //Job
            if (job != null)
            {
                rawBody = rawBody.Replace("#VacancyTitle#", job.JobTitle);
                rawBody = rawBody.Replace("#VacancyRef#", job.Ref);
                rawBody = rawBody.Replace("#VacancyBenefits#", job.Benefits);
                rawBody = rawBody.Replace("#VacancyOverview#", job.Overview);
            }


            // User
            if (cUser != null)
            {
                rawBody = rawBody.Replace("#UserForename#", cUser.Forename);
                rawBody = rawBody.Replace("#UserSurname#", cUser.Surname);
                rawBody = rawBody.Replace("#UserEmail#", cUser.Email);
                rawBody = rawBody.Replace("#UserMobile#", cUser.Mobile);
                rawBody = rawBody.Replace("#UserPassword#", cUser.Password);
                rawBody = rawBody.Replace("#UserJobTitle#", cUser.JobTitle);
            }

            // Consultant
            if (consultant != null)
            {
                rawBody = rawBody.Replace("#ConsultantForename#", consultant.Forename);
                rawBody = rawBody.Replace("#ConsultantSurname#", consultant.Surname);
                rawBody = rawBody.Replace("#ConsultantEmail#", consultant.Email);
                rawBody = rawBody.Replace("#ConsultantMobile#", consultant.Mobile);
                rawBody = rawBody.Replace("#ConsultantJobTitle#", consultant.Password);
            }


            // Client
            if (client != null)
            {
                rawBody = rawBody.Replace("#ClientName#", client.ClientName);
                rawBody = rawBody.Replace("#ClientEmail#", client.Email);
            }


            // Interview Request  
            if (intRequest != null)
            {
                var requestLink = "http://www.resonatesearch.co.uk/interview/interview-request.aspx?ref=" + intRequest.RefId;
                rawBody = rawBody.Replace("#InterviewRequestLink#", requestLink);
            }

            // Time Slot
            if (timeSlot != null)
            {
                rawBody = rawBody.Replace("#InterviewDate#", "Interview Date: <b>" + Convert.ToDateTime(timeSlot.SlotDate).ToString("dd MMM, yyyy") + " - " + timeSlot.SlotTime + "</b>");
                rawBody = rawBody.Replace("#Duration#", "Duration:<b> " + GetDurationText(timeSlot.Duration) + "</b>");
                rawBody = rawBody.Replace("#InterviewLocation#", timeSlot.Location != null ? GetInterviewLocation(timeSlot) : "");
                rawBody = rawBody.Replace("#Interviewers#", timeSlot.Interviewers != null && timeSlot.Interviewers.Any() ? GetInterviewers(timeSlot) : "");
            }

            return rawBody;
        }
Пример #7
0
        /// <summary>
        /// This function gets the calendar items
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public IEnumerable<CalendarEvent> GetCalendarEvents(CalendarFilter filter)
        {
            var events = new List<CalendarEvent>();
            // setup the parameters
            SqlParameter[] parameters = {
	                       new SqlParameter("@DateFrom", string.IsNullOrEmpty(filter.DateFrom) ? "" : new Utils().GetValidDate(filter.DateFrom) ),
	                       new SqlParameter("@DateTo ",  string.IsNullOrEmpty(filter.DateTo) ? ""  : new Utils().GetValidDate(filter.DateTo)  ),
                           new SqlParameter("@UserIds", string.IsNullOrEmpty(filter.UserIds) ? "" : filter.UserIds.Trim().TrimEnd(Convert.ToChar(","))), 
                           new SqlParameter("@EventIds", string.IsNullOrEmpty(filter.EventIds) ? "" : filter.EventIds.Trim().TrimEnd(Convert.ToChar(","))), 
                           new SqlParameter("@AllDay", filter.AllDay ),
                           new SqlParameter("@ClientId", filter.ClientId),
                           new SqlParameter("@VacancyId", filter.VacancyId) 
            };
            // setup the connection
            var conn = new Sql_DataAccess(_connString);
            var ds = conn.GetDataSetFromSP("RetrieveCalendarEvents", parameters);
            // iterate and return clients
            if (ds != null && ds.Tables.Count > 0)
            {
                events = (from DataRow dr in ds.Tables[0].Rows
                          select new CalendarEvent
                          {
                              EndDate = ((DateTime)dr["EndDate"]).ToString("s"),
                              StartDate = ((DateTime)dr["StartDate"]).ToString("s"),
                              Title = (dr["Title"] ?? "").ToString(),
                              Location = (dr["Location"] ?? "").ToString(),
                              EventId = (int)dr["EventId"],
                              RecurrenceId = (int)(dr["RecurrenceId"]),
                              IsDayEvent = (bool)dr["AllDayEvent"],
                              UserId = (int)dr["UserId"],
                              Locked = ((bool)dr["Locked"]),
                              CalendarColor = (dr["CalendarColor"] ?? "").ToString()
                          }).ToList();
            }

            if (string.IsNullOrEmpty(filter.EventIds))
            {
                var userIds = string.IsNullOrEmpty(filter.UserIds) ? "" : filter.UserIds.Trim().TrimEnd(Convert.ToChar(","));

                //get calendar events  
                var calEvents = GetOutlookEvents(userIds, Convert.ToDateTime(filter.DateFrom), Convert.ToDateTime(filter.DateTo));
                events.AddRange(calEvents);

                //get interviews
                var interviews = new Interviews().GetCalendarInterviews(userIds, Convert.ToDateTime(filter.DateFrom), Convert.ToDateTime(filter.DateTo));
                events.AddRange(interviews);
            }

         

            return events;
        }
Пример #8
0
        /// <summary>
        /// This function sends the email and save a record to the database
        /// </summary>
        /// <param name="emailRequest"></param>
        /// <returns></returns>
        // ReSharper disable once FunctionComplexityOverflow
        public PostEmailResponse SendContactEmails(PostEmailRequest emailRequest)
        {
            // init the response object
            var response = new PostEmailResponse { IsSuccess = true, ErrorContacts = new List<EmailSmsError>() };
            try
            {
                User fromUser = null;
                User consultant = null;
                Job job = null;
                User sendUser = null;

                // Retrieve objects if an id passed
                if (emailRequest.JobId > 0)
                    job = new Jobs().GetJob(emailRequest.JobId);
                // get the user if user id passed- who is sending
                if (emailRequest.SentBy > 0)
                    sendUser = new Users().GetUser(emailRequest.SentBy);
                //get the from address
                if (emailRequest.FromUserId > 0)
                    fromUser = new Users().GetUser(emailRequest.FromUserId);

                //Get the consultant/user object
                if (emailRequest.ConsultantId > 0 || (fromUser != null && fromUser.UserType.UserTypeId == 1))
                {
                    consultant = emailRequest.ConsultantId > 0 ? new Users().GetUser(emailRequest.ConsultantId) : fromUser;
                }

                emailRequest.RawBody = Utils.GetFullEmailReplacingMainTemplateTags(emailRequest.FromUserId, emailRequest.RawBody, true, true, false);
                var toAddressesToAppend = "This email has been sent to following contacts, <br />";

                // Get contacts for the filters or sent ids)
                var contactsAndClients = new ClientsAndContacts().GetClientContactsForEmailAndSms(emailRequest.SelectedContactIds, emailRequest.SelectedClientIds);


                //iterate through the contacts and send the sms
                foreach (var obj in contactsAndClients)
                {
                    var contact = obj.ClientOrContact as Candidate;
                    var client = obj.ClientOrContact as Client;
                    EmailSmsError errorContact = null;
                    var email = new Email();

                    // consultant id (if consultant id passed the use that else check whether the from user is a consultant and use that for tags )
                    var consultantId = emailRequest.ConsultantId > 0 ? emailRequest.ConsultantId : ((fromUser != null && fromUser.UserType.UserTypeId == 1) ? fromUser.UserId : 0);

                    // check for the contact email
                    if (contact != null && contact.DoNotEmail)
                    {
                        errorContact = new EmailSmsError { ContactId = contact != null ? contact.CandidateId : (client != null ? client.ClientId : -1), Error = "Contact prefence is not to send emails." };
                        response.ErrorContacts.Add(errorContact);
                    }
                    else if ((contact != null && !string.IsNullOrEmpty(contact.Email)) || (client != null && !string.IsNullOrEmpty(client.Email)))
                    {
                        var intRequestId = 0;
                        // set the interview request
                        if (emailRequest.InterviewRequestId > 0)
                        {
                            intRequestId = emailRequest.InterviewRequestId;
                        }
                        else if (emailRequest.InterviewId > 0)
                        {
                            // interview request email
                            var request = new InterviewRequest
                            {
                                InterviewId = emailRequest.InterviewId,
                                ContactId = contact.CandidateId
                            };
                            intRequestId = new Interviews().AddInterviewRequest(request);
                        }

                        // get the original message 
                        emailRequest.Body = new Utils().GetOriginalBody(emailRequest.RawBody, (contact != null ? contact.CandidateId : -1),
                            emailRequest.JobId, emailRequest.SentBy, consultantId, (client != null ? client.ClientId : -1), contact, job, sendUser, consultant, client, intRequestId, emailRequest.TimeSlotId);

                        //set the to address
                        email.ToAddress = new Recipient
                        {
                            MailAddress = contact != null ? contact.Email : (client != null ? client.Email : ""),
                            DisplayName = contact != null ? (contact.Forename + " " + contact.Surname) : (client != null ? client.ClientName : "")
                        };


                        if (contact != null)
                            toAddressesToAppend += ("&nbsp;&nbsp; - ") + ("\t" + contact.Forename + " " + contact.Surname);
                        else if (client != null)
                            toAddressesToAppend += ("&nbsp;&nbsp; - ") + ("\t" + client.ClientName);
                        toAddressesToAppend += "<br />";

                        // set the from email address with display name
                        if (fromUser != null)
                        {
                            email.FromAddress = new Recipient
                            {
                                MailAddress = fromUser.Email,
                                DisplayName = fromUser.Forename + " " + fromUser.Surname
                            };
                        }
                        else
                        {
                            email.FromAddress = new Recipient
                            {
                                MailAddress = "*****@*****.**",
                                DisplayName = "Resonate Search and Selection"
                            };
                        }

                        email.Subject = emailRequest.Subject;
                        email.Body = emailRequest.Body;
                        email.Attachments = emailRequest.Attachments;
                        // set the guid of not passed
                        email.Guid = string.IsNullOrEmpty(emailRequest.Guid) ? Guid.NewGuid().ToString() : emailRequest.Guid;
                        // send Email
                        try
                        {
                            SendEmail(email);
                        }
                        catch (Exception ex)
                        {
                            //error sending the sms 
                            errorContact = new EmailSmsError { ContactId = contact != null ? contact.CandidateId : (client != null ? client.ClientId : -1), Error = ex.ToString() };
                            response.ErrorContacts.Add(errorContact);
                        }
                    }
                    else
                    {
                        errorContact = new EmailSmsError { ContactId = contact != null ? contact.CandidateId : (client != null ? client.ClientId : -1), Error = "Email Address not found for the " + contact != null ? "contact" : "client" + "!" };
                        response.ErrorContacts.Add(errorContact);
                    }

                    // On success save Email into the database
                    var context = new dbDataContext();
                    var objEmail = new tbl_Email
                    {
                        Body = email.Body,
                        FromAddress = (email != null && email.FromAddress != null) ? email.FromAddress.MailAddress : "",
                        RefId = contact != null ? contact.CandidateId : (client != null ? client.ClientId : -1),
                        RefType = emailRequest.Type,
                        Subject = emailRequest.Subject,
                        SentBy = emailRequest.SentBy,
                        SentDate = DateTime.Now,
                        UserId = emailRequest.FromUserId,
                        Consultant = consultantId,
                        RawBody = emailRequest.RawBody,
                        HasAttachments = (emailRequest.Attachments != null && emailRequest.Attachments.Count > 0),
                        Error = errorContact != null ? errorContact.Error : "",
                        IsError = errorContact != null,
                        Guid = string.IsNullOrEmpty(email.Guid) ? Guid.NewGuid().ToString() : email.Guid,
                        ToAddress = (email != null && email.ToAddress != null) ? email.ToAddress.MailAddress : "",
                        EmailType = "OUT",
                        CcAddresses =
                            emailRequest.CcAddresses != null
                                ? (emailRequest.CcAddresses.Aggregate("", (current, to) => current + (to + ";")))
                                : ""
                    };
                    context.tbl_Emails.InsertOnSubmit(objEmail);
                    context.SubmitChanges();

                    if (errorContact == null)
                    {
                        // Add History 
                        new Histories().AddHistory(new History
                        {
                            RefId = contact != null ? contact.CandidateId : (client != null ? client.ClientId : -1),
                            RefType = contact != null ? "Contact" : "Client",
                            ClientUserId = emailRequest.FromUserId,
                            TypeId = 8,
                            SubRefType = "Email",
                            SubRefId = objEmail.EmailId
                        });
                    }

                    // save attachments into the email location
                    try
                    {
                        var sourcePath = HttpContext.Current.Server.MapPath("/system/temp/" + email.Guid + "/");
                        var destLocation =
                            HttpContext.Current.Server.MapPath("/system/email/" + objEmail.EmailId + "/");
                        if (!Directory.Exists(destLocation))
                            Directory.CreateDirectory(destLocation);
                        if (Directory.Exists(destLocation) && Directory.Exists(sourcePath))
                            Directory.GetFiles(sourcePath)
                                .ToList()
                                .ForEach(f => File.Copy(f, destLocation + "/" + Path.GetFileName(f)));
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                }
                //Send Copies
                if (emailRequest.CcAddresses != null)
                    SendEmailCopy(emailRequest, toAddressesToAppend, fromUser);
            }
            catch (Exception e)
            {
                response.IsSuccess = false;
                response.Error = e.ToString();
            }
            return response;

        }