コード例 #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
        public override void ItemUpdated(SPItemEventProperties properties)
        {
            base.ItemUpdated(properties);

            try
            {
                int itemID = Convert.ToInt32(properties.ListItemId);
                ChangeShiftManagementDAL notovertimeDAL = new ChangeShiftManagementDAL(properties.WebUrl);
                var    item = notovertimeDAL.GetByID(itemID);
                string url  = string.Empty;
                if (item != null)
                {
                    SPUser currentUser = properties.Web.CurrentUser;
                    if (item.ApprovalStatus.Equals("1"))
                    {
                        var changeShiftRequestMailService           = string.Format("{0}/_vti_bin/Services/Email/EmailService.svc/SendChangeShiftRequestMail/{1}/{2}", properties.WebUrl, itemID, "BOD");
                        var delegationChangeShiftRequestMailService = string.Format("{0}/_vti_bin/Services/Email/EmailService.svc/SendDelegationChangeShiftRequestMail/{1}/{2}", properties.WebUrl, itemID, "BOD");
                        CallService(changeShiftRequestMailService);
                        CallService(delegationChangeShiftRequestMailService);
                    }
                    else if (item.ApprovalStatus.Equals("Approved"))
                    {
                        //update new shift
                        string updateShiftUrl = string.Format("{0}/_vti_bin/Services/ShiftManagement/ShiftManagementService.svc/UpdateShiftDetailForWorkflow/{1}/{2}/{3}/{4}",
                                                              properties.WebUrl, item.Requester.LookupId, item.FromDate.ToString(StringConstant.DateFormatMMddyyyy), item.ToDate.ToString(StringConstant.DateFormatMMddyyyy), item.ToShift.LookupId);
                        CallService(updateShiftUrl);
                    }
                }
            }
            catch (Exception ex)
            {
                ULSLogging.Log(new SPDiagnosticsCategory("STADA - ChangeShiftEventReceiver - ItemUpdated fn",
                                                         TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected,
                               string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace));
            }
        }
コード例 #3
0
        public MessageResult Approve(ChangeShiftApprovalModel changeShiftApprovalModel)
        {
            MessageResult msgResult = new MessageResult();

            try
            {
                SPWeb spWeb = SPContext.Current.Web;

                if (changeShiftApprovalModel.Id > 0)
                {
                    Biz.Models.ChangeShiftManagement changeShiftManagement = _changeShiftManagementDAL.GetByID(changeShiftApprovalModel.Id);
                    string currentApprovalStatus = !string.IsNullOrEmpty(changeShiftManagement.ApprovalStatus) ? changeShiftManagement.ApprovalStatus.ToLower() : string.Empty;
                    if (currentApprovalStatus == ApprovalStatus.Approved.ToLower() || currentApprovalStatus == ApprovalStatus.Cancelled.ToLower() || currentApprovalStatus == ApprovalStatus.Rejected.ToLower())
                    {
                        return(new MessageResult {
                            Code = (int)ChangeShiftErrorCode.CannotApprove, Message = MessageResultHelper.GetRequestStatusMessage(currentApprovalStatus), ObjectId = 0
                        });
                    }

                    string requestExpiredMsg = MessageResultHelper.GetRequestExpiredMessage(changeShiftManagement.RequestDueDate);
                    if (!string.IsNullOrEmpty(requestExpiredMsg))
                    {
                        return(new MessageResult {
                            Code = (int)BusinessTripErrorCode.CannotApprove, Message = requestExpiredMsg, ObjectId = 0
                        });
                    }

                    bool            hasApprovalPermission = false;
                    EmployeeInfoDAL _employeeInfoDAL      = new EmployeeInfoDAL(spWeb.Url);
                    int             approverId            = changeShiftApprovalModel.ApproverId;
                    approverId = approverId > 0 ? approverId : changeShiftManagement.DepartmentHead.ID;
                    EmployeeInfo currentApprover = _employeeInfoDAL.GetByADAccount(approverId);
                    if (currentApprover != null)
                    {
                        if (currentApprover.ADAccount.ID == spWeb.CurrentUser.ID)
                        {
                            hasApprovalPermission = true;
                        }
                        else
                        {
                            Delegation delegation = DelegationPermissionManager.IsDelegation(currentApprover.ID, StringConstant.ChangeShiftList.ListUrl, changeShiftManagement.ID);
                            if (delegation != null)
                            {
                                hasApprovalPermission = true;
                            }
                        }
                    }

                    if (hasApprovalPermission == true)
                    {
                        changeShiftManagement.ApprovalStatus = ApprovalStatus.Approved;
                        changeShiftManagement.Comment        = changeShiftApprovalModel.Comment;
                        var approver = spWeb.AllUsers.GetByID(approverId);
                        changeShiftManagement.DepartmentHead = new User
                        {
                            UserName = approver.LoginName,
                            FullName = approver.Name
                        };
                        _changeShiftManagementDAL.SaveItem(changeShiftManagement);

                        // Send approval email to employee
                        SendEmail(spWeb.Url, changeShiftApprovalModel.Id, "ChangeShift_Approve", changeShiftApprovalModel.ApproverName);
                    }
                }
            }
            catch (Exception ex)
            {
                msgResult.Code    = (int)ChangeShiftErrorCode.Unexpected;
                msgResult.Message = ex.Message;
            }

            return(msgResult);
        }