Esempio n. 1
0
 /// <summary>
 /// This function validates the user
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public User ValidateUser(string username, string password)
 {
     var context = new dbDataContext();
     // Set up the query to retrieve user
     var user = context.tbl_Users.FirstOrDefault(t => String.Compare(t.Email, username, StringComparison.OrdinalIgnoreCase) == 0 &&
         String.Compare(t.Password, password, StringComparison.OrdinalIgnoreCase) == 0 && !t.Deleted && t.IsActive);
     if (user != null)
     {
         var cUser = new User
         {
             UserId = user.UserId,
             Forename = user.Forename,
             Surname = user.Surname,
             JobTitle = user.JobTitle,
             Email = user.Email,
             Password = user.Password,
             Telephone = user.Telephone,
             CreatedDate = user.CreatedDate,
             Fax = user.Fax,
             Mobile = user.Mobile,
             FullName = user.Forename + " " + user.Surname,
             Deleted = user.Deleted,
             IsActive = user.IsActive,
             CalendarColor = user.CalendarColor,
             UserType = GetUserType(user.UserType)
         };
         var docs = Documents.GetDocumentByDocType(new[] { 10 }, cUser.UserId).ToList();
         if (docs.Count > 0)
         {
             cUser.ProfileImage = docs[0];
         }
         return cUser;
     }
     return null;
 }
Esempio n. 2
0
 /// <summary>
 /// This function gets the user by id
 /// </summary>
 /// <param name="id"></param> 
 /// <returns></returns>
 public User GetUser(int id)
 {
     var context = new dbDataContext();
     // Set up the query to retrieve user
     var user = context.tbl_Users.FirstOrDefault(t => t.UserId == id);
     if (user != null)
     {
         var cUser = new User
        {
            UserId = user.UserId,
            Forename = user.Forename,
            Surname = user.Surname,
            JobTitle = user.JobTitle,
            Email = user.Email,
            Password = user.Password,
            Telephone = user.Telephone,
            CreatedDate = user.CreatedDate,
            Fax = user.Fax,
            Mobile = user.Mobile,
            CalendarColor = user.CalendarColor,
            FullName = user.Forename + " " + user.Surname,
            Deleted = user.Deleted,
            UserType = GetUserType(user.UserType),
            FooterTemplate = GetFooterTemplate(id),
            IsActive = user.IsActive
        };
         var docs = Documents.GetDocumentByDocType(new[] { 10 }, cUser.UserId).ToList();
         if (docs.Count > 0)
         {
             cUser.ProfileImage = docs[0];
         }
         return cUser;
     }
     return null;
 }
Esempio n. 3
0
        /// <summary>
        /// This function add/edit users
        /// </summary>
        /// <param name="user"></param>
        public int AddEditUsers(User user)
        {
            var context = new dbDataContext();
            var cUser = context.tbl_Users.FirstOrDefault(t => t.UserId == user.UserId) ??
                        new tbl_User();

            // Assign user values
            cUser.Email = user.Email;
            cUser.Forename = user.Forename;
            cUser.Surname = user.Surname;
            if (!string.IsNullOrEmpty(user.Password))
            {
                cUser.Password = user.Password;
            }
            cUser.JobTitle = user.JobTitle;
            cUser.Mobile = user.Mobile;
            cUser.Telephone = user.Telephone;
            cUser.UserType = user.UserType.UserTypeId;
            cUser.Deleted = user.Deleted;
            var isAdd = false;
            try
            {
                // Add/Update user
                if (cUser.UserId <= 0)
                {
                    isAdd = true;
                    cUser.CreatedDate = DateTime.Now;
                    cUser.LastOutlookCalendarSyncDate = DateTime.Now;
                    cUser.LastOutlookEmailSyncDate = DateTime.Now;
                    context.tbl_Users.InsertOnSubmit(cUser);
                }
                context.SubmitChanges();

                //save the footer template
                var fTemplate = context.tbl_EmailFooters.FirstOrDefault(t => t.ClientUserId == user.UserId);
                if (user.FooterTemplate != null)
                {
                    if (fTemplate == null)
                        fTemplate = new tbl_EmailFooter();
                    fTemplate.ClientUserId = cUser.UserId;
                    fTemplate.FooterTemplate = user.FooterTemplate.Template;
                    fTemplate.InUse = true;
                    if (fTemplate.FooterTemplateId <= 0)
                        context.tbl_EmailFooters.InsertOnSubmit(fTemplate);
                }
                else if (fTemplate != null) // template found, but not in use
                    fTemplate.InUse = false;
                // submit the changes
                context.SubmitChanges();
            }
            catch (Exception)
            {
                return -1;
            }
            // Add History
            new Histories().AddHistory(new History
            {
                RefId = user.UserId,
                RefType = "User",
                ClientUserId = user.UpdatedBy,
                TypeId = isAdd ? 12 : 13,
                SubRefType = "User",
                SubRefId = user.UpdatedBy
            });

            return cUser.UserId;
        }
Esempio n. 4
0
 /// <summary>
 /// This function replace the user tahs from footer
 /// </summary>
 /// <param name="rawBody"></param>
 /// <param name="userId"></param>
 /// <param name="cUser"></param>
 /// <returns></returns>
 public static string GetOriginalFooter(string rawBody, int userId, User cUser = null)
 {
     if (cUser == null && userId > 0)
         cUser = new Users().GetUser(userId);
     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);
     }
     else
         rawBody = rawBody.Replace("#UserForename#", "")
             .Replace("#UserSurname#", "")
             .Replace("#UserEmail#", "")
             .Replace("#UserMobile#", "").Replace("#UserPassword#", "").Replace("#UserJobTitle#", "");
     return rawBody;
 }
Esempio n. 5
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;
        }
Esempio n. 6
0
        /// <summary>
        /// This function sends copies
        /// </summary>
        /// <param name="emailRequest"></param>
        /// <param name="appendToAddresses"></param>
        /// <param name="fromUser"></param>
        private void SendEmailCopy(PostEmailRequest emailRequest, string appendToAddresses, User fromUser)
        {
            emailRequest.RawBody = appendToAddresses + "<br/>" + emailRequest.RawBody;

            foreach (var ccEmail in emailRequest.CcAddresses)
            {
                try
                {
                    var email = new Email
                    {
                        Subject = emailRequest.Subject,
                        ToAddress = new Recipient { MailAddress = ccEmail },
                        FromAddress = new Recipient
                        {
                            MailAddress = fromUser.Email,
                            DisplayName = fromUser.Forename + " " + fromUser.Surname
                        },
                        Body = emailRequest.RawBody,
                        Attachments = emailRequest.Attachments
                    };
                    // set the from email address with display name
                    SendEmail(email);
                }
                catch (Exception)
                {
                    // ignored
                }
            }
        }