public bool SendMail(CConstValue.Approval approvalType, CConstValue.MailStatus mailStatus, int index, string indexNumber, int userId) { try { var requestedUserId = 0; DateTime requestedDate = DateTime.Now; var approvedUserId = 0; var approvedMemo = string.Empty; DateTime approvedDate = DateTime.Now; var approvingUserId = 0; var approvalStatus = string.Empty; var currentApproval = new CApprovalHistory().GetCurrentApproval((int)approvalType, index); if (currentApproval != null) { var approvalStepDict = new CDict().GetDictByTypeAndValue(217, (int)currentApproval.ApprovalStep); approvalStatus = approvalStepDict?.Name; approvedMemo = currentApproval.ApprovalMemo; approvedDate = currentApproval.ApprovalDate.Value; } switch (mailStatus) { case CConstValue.MailStatus.ToApproveUser: requestedUserId = userId; approvingUserId = new CApproval().GetSupuervisor((int)approvalType, userId); break; case CConstValue.MailStatus.ToApproveUserAndRequestUser: var tempRequestedUser1 = new CApprovalHistory().GetApprovalByRequestedUser((int)approvalType, index); if (tempRequestedUser1 != null) { requestedUserId = tempRequestedUser1.ApprovalUser; requestedDate = tempRequestedUser1.CreatedDate; } approvedUserId = userId; approvingUserId = new CApproval().GetSupuervisor((int)approvalType, userId); break; case CConstValue.MailStatus.ToRequestUser: var tempRequestedUser2 = new CApprovalHistory().GetApprovalByRequestedUser((int)approvalType, index); if (tempRequestedUser2 != null) { requestedUserId = tempRequestedUser2.ApprovalUser; requestedDate = tempRequestedUser2.CreatedDate; } approvedUserId = userId; break; } var cUser = new CUser(); var requestedUser = cUser.Get(requestedUserId); var approvedUser = cUser.Get(approvedUserId); var approvingUser = cUser.Get(approvingUserId); if (indexNumber == string.Empty) { indexNumber = index.ToString(); } // todo : temp to change mail should be removed before lunching. if (requestedUser != null) { requestedUser.Email = "*****@*****.**"; } if (approvedUser != null) { approvedUser.Email = "*****@*****.**"; } if (approvingUser != null) { approvingUser.Email = "*****@*****.**"; } var bodyToApprovingUser = $@"Dear <u><i>{cUser.GetUserName(approvingUser)}</i></u>, <p></p><br /><br /> A new request is waiting for your approval. <br /><br /> Please check it out. <p></p><br /><br /> <b>{approvalType}</b> <br /><br /> - No : <b>{indexNumber}</b> <br /> - Status : <b>{approvalStatus}</b> <br /> - Requested by : <b>{cUser.GetUserName(requestedUser)}</b> <br /> - Requested Date : <b>{CGlobal.GetDateFormat(requestedDate)}</b>"; var bodyToRequestedUser = $@"Dear <u><i>{cUser.GetUserName(requestedUser)}</i></u>, <p></p><br /><br /> Your request has been updated. <br /><br /> Please check it out. <p></p><br /><br /> <b>{approvalType}</b> <br /><br /> - No : <b>{indexNumber}</b> <br /> - Status : <b>{approvalStatus}</b> <br /> - Approved by : <b>{cUser.GetUserName(approvedUser)}</b> <br /> - Approved Date : <b>{CGlobal.GetDateFormat(approvedDate)}</b> <br /> - Approved Memo : <b>{approvedMemo}</b>"; switch (mailStatus) { case CConstValue.MailStatus.ToApproveUser: SendMailPost(approvalType.ToString(), approvingUser.Email, bodyToApprovingUser); break; case CConstValue.MailStatus.ToApproveUserAndRequestUser: SendMailPost(approvalType.ToString(), requestedUser.Email, bodyToRequestedUser); SendMailPost(approvalType.ToString(), approvingUser.Email, bodyToApprovingUser); break; case CConstValue.MailStatus.ToRequestUser: SendMailPost(approvalType.ToString(), requestedUser.Email, bodyToRequestedUser); break; } } catch (Exception ex) { Debug.Print(ex.Message); return(false); } return(true); }
public int ApproveRequstCreate(int approveType, int myId, int menuSeqId) { try { var qryMy = _db.Approvals.Where(q => q.IsActive && q.ApproveType == approveType && q.UserId == myId).FirstOrDefault(); if (qryMy != null) { //기안자 결재(approvalhistory add) var cInqry = new CApprovalHistory(); var inqry = new ApprovalHistory(); inqry.ApproveType = approveType; inqry.MenuSeqId = menuSeqId; inqry.ApprovalUser = qryMy.UserId; inqry.ApprovalDate = DateTime.Now; inqry.IsApprovalRequest = true; inqry.ApprovalStep = qryMy.Supervisor == null ? new CGlobal().GetApprovalValue(approveType) : 1; // auto approved or requested inqry.CreatedId = myId; inqry.CreatedDate = DateTime.Now; cInqry.Add(inqry); if (qryMy.Supervisor != null) { int?supervisorId = Convert.ToInt32(qryMy.Supervisor); var flg = true; while (supervisorId != null) { //결재자들 결재 생성 var super = _db.Approvals.Where(q => q.IsActive && q.ApproveType == approveType && q.UserId == supervisorId).FirstOrDefault(); var cSubInqry = new CApprovalHistory(); var subInqry = new ApprovalHistory(); subInqry.ApproveType = approveType; subInqry.MenuSeqId = menuSeqId; subInqry.ApprovalUser = super.UserId; subInqry.CreatedId = myId; subInqry.CreatedDate = DateTime.Now; if (flg) { subInqry.IsApprovalRequest = true; flg = false; } cSubInqry.Add(subInqry); supervisorId = super.Supervisor; } } return((int)inqry.ApprovalStep); } } catch (Exception ex) { Debug.Print(ex.Message); } return(-1); }