Пример #1
0
        /// <summary>
        /// Send email to Requester after
        /// </summary>
        /// <param name="changeshiftItemId"></param>
        /// <returns></returns>
        /// CALL URL: /_vti_bin/Services/Email/EmailService.svc/SendChangeShiftRequestMail/1/BOD
        public bool SendChangeShiftRequestMail(string changeshiftItemId, string toRole)
        {
            try
            {
                int idValue;
                if (int.TryParse(changeshiftItemId, out idValue))
                {
                    var changeShiftManagementItem  = _changeShiftManagementDAL.GetByID(idValue);
                    var changeshiftRequestMailItem = _emailTemplateDAL.GetByKey("ChangeShift_Request");
                    if (changeshiftRequestMailItem != null && changeShiftManagementItem != null)
                    {
                        string email            = string.Empty;
                        string employeeFullname = string.Empty;
                        string link             = string.Empty;
                        if (toRole.Equals("DH"))
                        {
                            var accountDHItem = _employeeDAL.GetByADAccount(changeShiftManagementItem.DepartmentHead.ID);
                            email            = accountDHItem.Email;
                            employeeFullname = accountDHItem.FullName;
                            link             = $"{WebUrl}/{StringConstant.WebPageLinks.ChangeShiftManager}";
                        }
                        else if (toRole.Equals("BOD"))
                        {
                            var accountBODItem = _employeeDAL.GetByADAccount(changeShiftManagementItem.BOD.ID);
                            email            = accountBODItem.Email;
                            employeeFullname = accountBODItem.FullName;
                            link             = $"{WebUrl}/{StringConstant.WebPageLinks.ChangeShiftBOD}";
                        }

                        if (!string.IsNullOrEmpty(email))
                        {
                            var shiftTimeList = _shiftTimeDAL.GetShiftTimes();

                            string emailBody = HTTPUtility.HtmlDecode(changeshiftRequestMailItem.MailBody);
                            //lookup email
                            var fromShiftItem = shiftTimeList.Where(x => x.ID == changeShiftManagementItem.FromShift.LookupId).FirstOrDefault();
                            var toShiftItem   = shiftTimeList.Where(x => x.ID == changeShiftManagementItem.ToShift.LookupId).FirstOrDefault();

                            emailBody = string.Format(emailBody, employeeFullname, changeShiftManagementItem.Requester.LookupValue,
                                                      changeShiftManagementItem.FromDate.ToString(StringConstant.DateFormatddMMyyyy2),
                                                      changeShiftManagementItem.ToDate.ToString(StringConstant.DateFormatddMMyyyy2),
                                                      changeShiftManagementItem.Reason, fromShiftItem.Code, toShiftItem.Code);

                            emailBody = emailBody.Replace("#link", link);
                            _sendMailActivity.SendMail(SPContext.Current.Web.Url, changeshiftRequestMailItem.MailSubject, email, true, false, emailBody);
                            return(true);
                        }
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                ULSLogging.Log(new SPDiagnosticsCategory("STADA - Email Service - SendChangeShiftRequestMail fn",
                                                         TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected,
                               string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace));
                return(false);
            }
        }
Пример #2
0
 /// <summary>
 /// Get all Shift Time
 /// </summary>
 /// <returns></returns>
 /// CALL URL: _vti_bin/Services/ShiftTime/ShiftTimeService.svc/GetShiftTimes
 public List <ShiftTimeModel> GetShiftTimes()
 {
     try
     {
         List <ShiftTimeModel> shiftTimes = new List <ShiftTimeModel>();
         var shiftTimeList = _shiftTimeDAL.GetShiftTimes();
         if (shiftTimeList.Any())
         {
             foreach (var item in shiftTimeList)
             {
                 shiftTimes.Add(
                     this.ConvertToShiftTimeModel(item)
                     );
             }
         }
         return(shiftTimes);
     }
     catch (Exception ex)
     {
         ULSLogging.Log(new SPDiagnosticsCategory("STADA - Shift Time Service - GetShiftTimes fn",
                                                  TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected,
                        string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace));
         return(null);
     }
 }
        private void SendEmail(string webUrl, int changeshiftItemId, string emailKey, string approverFullName)
        {
            SendEmailActivity sendMailActity = new SendEmailActivity();

            Thread thread = new Thread(delegate()
            {
                var _emailTemplateDAL          = new EmailTemplateDAL(webUrl);
                var _employeeDAL               = new EmployeeInfoDAL(webUrl);
                var _shiftTimeDAL              = new ShiftTimeDAL(webUrl);
                var _sendMailActivity          = new SendEmailActivity();
                var changeShiftManagementItem  = _changeShiftManagementDAL.GetByID(changeshiftItemId);
                var changeshiftRequestMailItem = _emailTemplateDAL.GetByKey(emailKey);
                if (changeshiftRequestMailItem != null && changeShiftManagementItem != null)
                {
                    var employee = _employeeDAL.GetByID(changeShiftManagementItem.Requester.LookupId);

                    if (employee != null && !string.IsNullOrEmpty(employee.Email))
                    {
                        var shiftTimeList = _shiftTimeDAL.GetShiftTimes();
                        string emailBody  = HTTPUtility.HtmlDecode(changeshiftRequestMailItem.MailBody);

                        var fromShiftItem = shiftTimeList.Where(x => x.ID == changeShiftManagementItem.FromShift.LookupId).FirstOrDefault();
                        var toShiftItem   = shiftTimeList.Where(x => x.ID == changeShiftManagementItem.ToShift.LookupId).FirstOrDefault();
                        //lookup email
                        string link = $"{webUrl}/{StringConstant.WebPageLinks.ChangeShiftMember}";
                        if (employee.EmployeePosition.LookupId == (int)StringConstant.EmployeePosition.Administrator)
                        {
                            link = $"{webUrl}/{StringConstant.WebPageLinks.ChangeShiftAdmin}";
                        }
                        if (employee.EmployeePosition.LookupId == (int)StringConstant.EmployeePosition.DepartmentHead)
                        {
                            link = $"{webUrl}/{StringConstant.WebPageLinks.ChangeShiftManager}";
                        }

                        emailBody = string.Format(emailBody, employee.FullName, changeShiftManagementItem.Requester.LookupValue,
                                                  changeShiftManagementItem.FromDate.ToString(StringConstant.DateFormatddMMyyyy2),
                                                  changeShiftManagementItem.ToDate.ToString(StringConstant.DateFormatddMMyyyy2),
                                                  changeShiftManagementItem.Reason, fromShiftItem.Code, toShiftItem.Code, changeShiftManagementItem.Comment, approverFullName);
                        emailBody = emailBody.Replace("#link", link);
                        _sendMailActivity.SendMail(webUrl, changeshiftRequestMailItem.MailSubject, employee.Email, true, false, emailBody);
                    }
                }
            });

            thread.IsBackground = true;
            thread.Start();
        }