Beispiel #1
0
        /// <summary>
        /// Check update date whether is valid
        /// </summary>
        /// <param name="objUI"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        private bool IsValidUpdateDate(SR_Setting objUI, SR_Setting objDb, out Message msg)
        {
            bool isValid = false;
            msg = null;

            try
            {
                if ((objUI != null) && (objUI.UpdateDate != null))
                {
                    if (objDb != null)
                    {
                        if (objDb.UpdateDate.ToString().Equals(objUI.UpdateDate.ToString()))
                        {
                            isValid = true;
                        }
                        else
                        {
                            msg = new Message(MessageConstants.E0025, MessageType.Error, "This setting");
                        }
                    }
                }
            }
            catch
            {
                throw;
            }

            return isValid;
        }
Beispiel #2
0
        private bool IsValidRoute(SR_Setting obj, out Message msg, bool isUpdate)
        {
            bool isDuplicated = false;
            SR_Setting objDb = new SR_Setting();
            msg = null;

            try
            {
                if (!isUpdate)
                {
                    if (!string.IsNullOrEmpty(obj.ProjectName))
                    {
                        objDb = dbContext.SR_Settings.Where(q =>  q.ProjectName == obj.ProjectName
                             && q.OfficeID == obj.OfficeID && q.DeleteFlag == false).FirstOrDefault();
                    }
                    else
                    {
                        objDb = dbContext.SR_Settings.Where(q => (q.ProjectName == null || q.ProjectName.Trim() == string.Empty)
                            && q.OfficeID == obj.OfficeID && q.DeleteFlag == false).FirstOrDefault();
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(obj.ProjectName))
                    {
                        objDb = dbContext.SR_Settings.Where(q => q.ProjectName == obj.ProjectName
                             && q.OfficeID == obj.OfficeID && q.ID != obj.ID && q.DeleteFlag == false).FirstOrDefault();
                    }
                    else
                    {
                        objDb = dbContext.SR_Settings.Where(q => (q.ProjectName == null || q.ProjectName.Trim() == string.Empty) &&
                            q.OfficeID == obj.OfficeID  && q.ID != obj.ID && q.DeleteFlag == false).FirstOrDefault();
                    }
                }
            }
            catch
            {
                throw;
            }
            if (objDb != null)
            {
                isDuplicated = true;
            }
            return isDuplicated;
        }
Beispiel #3
0
        /// <summary>
        /// Delete Service Request Setting
        /// </summary>
        /// <param name="objUI"></param>
        private void Delete(SR_Setting objUI)
        {
            if (objUI != null)
            {
                // Get current group in dbContext
                SR_Setting objDb = GetByID(objUI.ID);
                if (objDb != null)
                {
                    // Set delete info
                    objDb.DeleteFlag = true;
                    objDb.UpdateDate = DateTime.Now;
                    objDb.UpdatedBy = objUI.UpdatedBy;
                    // Submit changes to dbContext
                    dbContext.SubmitChanges();

                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Update Service Request Setting
        /// </summary>
        /// <param name="objUI"></param>
        /// <returns></returns>
        public Message Update(SR_Setting objUI)
        {
            Message msg = null;

            try
            {
                if (objUI != null)
                {
                    // Get current group in dbContext
                    SR_Setting objDb = GetByID(objUI.ID);

                    if (objDb != null)
                    {
                        // Check valid update date
                        if (!IsValidUpdateDate(objUI, objDb, out msg))
                        {
                            UserAdmin objUserAdmin = new UserAdminDao().GetById(objUI.UserAdminID);
                            msg = new Message(MessageConstants.E0025, MessageType.Error, "User Admin " + objUserAdmin != null ? objUserAdmin.UserName : string.Empty, "assigned to project " + objUI.ProjectName);
                        }
                        else if(IsDuplicated(objUI, out msg,true))
                        {
                            UserAdmin objUserAdmin = new UserAdminDao().GetById(objUI.UserAdminID);
                            msg = new Message(MessageConstants.E0004, MessageType.Error, "User Admin " + ( objUserAdmin != null ? objUserAdmin.UserName : string.Empty) +  " assigned to project " + objUI.ProjectName);
                        }
                        else if (IsValidRoute(objUI, out msg, true))
                        {
                            msg = new Message(MessageConstants.E0048, MessageType.Error, "The default routing");
                        }
                        else
                        {
                             // Update info by objUI
                            objDb.OfficeID = objUI.OfficeID;
                            objDb.ProjectName = objUI.ProjectName;
                            objDb.UserAdminID = objUI.UserAdminID;
                            objDb.IsActive = objUI.IsActive;
                            objDb.DeleteFlag = objUI.DeleteFlag;
                            objDb.UpdateDate = DateTime.Now;
                            objDb.UpdatedBy = objUI.UpdatedBy;
                            objDb.EmailTo = objUI.EmailTo;
                            objDb.EmailCc = objUI.EmailCc;
                            objDb.EmailBcc = objUI.EmailBcc;

                            // Submit changes to dbContext
                            dbContext.SubmitChanges();

                            // Show success message
                            UserAdmin objUserAdmin = new UserAdminDao().GetById(objUI.UserAdminID);
                            msg = new Message(MessageConstants.I0001, MessageType.Info, "User Admin " + objUserAdmin != null?objUserAdmin.UserName:string.Empty, "assigned to project " + objUI.ProjectName);
                        }
                    }
                }
            }
            catch
            {
                // Show system error
                msg = new Message(MessageConstants.E0007, MessageType.Error);
            }

            return msg;
        }
Beispiel #5
0
        /// <summary>
        /// Insert Service Request Setting
        /// </summary>
        /// <param name="objUI"></param>
        /// <returns></returns>
        public Message Insert(SR_Setting objUI)
        {
            Message msg = null;
            try
            {
                if (IsValidRoute(objUI, out msg, false))
                {
                    msg = new Message(MessageConstants.E0048, MessageType.Error, "The default routing");
                }
                else if (IsDuplicated(objUI, out msg, false))
                {
                    UserAdmin objUserAdmin = new UserAdminDao().GetById(objUI.UserAdminID);
                    msg = new Message(MessageConstants.E0004, MessageType.Error, "User Admin " + (objUserAdmin != null ? objUserAdmin.UserName : string.Empty) + " assigned to project " + objUI.ProjectName);
                }
                else
                {
                    dbContext.SR_Settings.InsertOnSubmit(objUI);
                    dbContext.SubmitChanges();
                    // Show success message
                    msg = new Message(MessageConstants.I0001, MessageType.Info, "User Admin " + objUI.UserAdmin.UserName, "assigned to project " + objUI.ProjectName);
                }

            }
            catch
            {
                msg = new Message(MessageConstants.E0007, MessageType.Error);
            }
            return msg;
        }
Beispiel #6
0
        /// <summary>
        /// Send SR_Request to only Requestor
        /// </summary>
        /// <param name="srId"></param>
        /// <param name="type"></param>
        public static void SendSRMailFromPortal(int srId, int type)
        {
            // Get body detail
            SR_ServiceRequest obj = new ServiceRequestDao().GetById(srId);

            //WFRole role = null;
            if (obj == null)
            {
                return;
            }

            string from_email = ConfigurationManager.AppSettings["from_email"];
            string host = ConfigurationManager.AppSettings["mailserver_host"];
            string port = ConfigurationManager.AppSettings["mailserver_port"];
            string poster = "Service Request";
            string subject = string.Empty;
            switch (type)
            {
                case Constants.SR_SEND_MAIL_COMMENT:
                    subject = "[CRM-SR] " + Constants.SR_SERVICE_REQUEST_PREFIX + obj.ID + " has been modified";
                    break;
                default:
                    if (obj.StatusID == Constants.SR_STATUS_CLOSED)
                    {
                        subject = "[CRM-SR] " + Constants.SR_SERVICE_REQUEST_PREFIX + obj.ID + " has been closed";
                    }
                    else
                    {
                        subject = "[CRM-SR] " + Constants.SR_SERVICE_REQUEST_PREFIX + obj.ID + " has been forwarded to " + obj.AssignUser;
                    }
                    break;
            }
            string body = CreateBodyOfEmail(obj);
            // string requestorBody = CreateRequestorBodyOfEmail(obj);

            string to_email = string.Empty;
            string cc_email = string.Empty;
            string[] arrIds = new string[] { };
            arrIds = obj.InvolveUser.Split(Constants.SEPARATE_INVOLVE_CHAR);
            List<string> sendList = new List<string>();
            List<string> duplicateEmail = new List<string>();

            for (int i = 0; i < arrIds.Length - 1; i++)
            {
                //check duplicate person on user name
                if (!sendList.Contains(arrIds[i]))
                {
                    sendList.Add(arrIds[i]);
                    if (obj.StatusID == Constants.SR_STATUS_CLOSED) //If an email has "Close" status, just only send by "To" section, not cc 
                    {
                        if (!duplicateEmail.Contains(arrIds[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";"))
                        {
                            // only send survey email to SubmitUser
                            if (i == 0)
                            {
                                string surveyBody = CreateSurveyBodyEmail(obj);
                                string survey_email = arrIds[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";";
                                WebUtils.SendMail(host, port, from_email, poster, survey_email, cc_email, subject, surveyBody);
                            }
                            else
                                to_email += arrIds[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";";
                            duplicateEmail.Add(arrIds[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";");
                        }
                    }
                    else
                    {
                        //Just send by "To" section only to person who has been assigned, the involved others are by "CC" section.
                        if (string.IsNullOrEmpty(to_email))
                        {
                            to_email = obj.AssignUser + Constants.LOGIGEAR_EMAIL_DOMAIN + ";";
                            cc_email = arrIds[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";";
                            duplicateEmail.Add(arrIds[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";");
                            duplicateEmail.Add(obj.AssignUser + Constants.LOGIGEAR_EMAIL_DOMAIN + ";");

                            cc_email = obj.RequestUser + Constants.LOGIGEAR_EMAIL_DOMAIN + ";";
                            duplicateEmail.Add(obj.RequestUser + Constants.LOGIGEAR_EMAIL_DOMAIN + ";");
                        }
                        else //make a cc list mail send.
                        {
                            if (!duplicateEmail.Contains(arrIds[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";"))
                            {
                                duplicateEmail.Add(arrIds[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";");
                                cc_email += arrIds[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";";
                            }
                        }
                    }
                }
            }
            if (!string.IsNullOrEmpty(obj.CCList))
            {
                string[] array = obj.CCList.Split(';');
                foreach (string item in array)
                {
                    if (!string.IsNullOrEmpty(item))
                    {
                        string userAdminID = item;
                        if (!duplicateEmail.Contains(item + Constants.LOGIGEAR_EMAIL_DOMAIN + ";"))
                        {
                            duplicateEmail.Add(item + Constants.LOGIGEAR_EMAIL_DOMAIN + ";");
                            cc_email += item + Constants.LOGIGEAR_EMAIL_DOMAIN + ";";
                        }
                    }
                }
            }
            #region Get default email from routing page

            ServiceRequestDao srDao = new ServiceRequestDao();
            EmployeeDao emplDao = new EmployeeDao();
            SRSettingDao srSettingDao = new SRSettingDao();
            SR_Setting srSetting = new SR_Setting();
            string bcc_email = String.Empty;
            string[] aTo = new string[] { };
            string[] aCc = new string[] { };
            string[] aBcc = new string[] { };
            string locationCode = (emplDao.GetByOfficeEmail((obj.RequestUser + Constants.LOGIGEAR_EMAIL_DOMAIN).Trim()) as Employee).LocationCode;
            if (!String.IsNullOrEmpty(locationCode))
            {
                int officeId = ConvertUtil.ConvertToInt(CommonFunc.GetLocation(locationCode, LocationType.Office));
                string proName = (emplDao.GetByOfficeEmail(obj.RequestUser + Constants.LOGIGEAR_EMAIL_DOMAIN) as Employee).Project;
                if (String.IsNullOrEmpty(proName))
                {
                    srSetting = srSettingDao.GetByProjectAndOffice(String.Empty, officeId);
                }
                else
                {
                    srSetting = srSettingDao.GetByProjectAndOffice(proName, officeId);
                }
                if (!string.IsNullOrEmpty(srSetting.EmailTo))
                {
                    aTo = srSetting.EmailTo.Split(Constants.SEPARATE_CC_LIST);
                    for (int i = 0; i < aTo.Count(); i++)
                    {
                        if (!duplicateEmail.Contains(aTo[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";") && !String.IsNullOrEmpty(aTo[i]))
                        {
                            duplicateEmail.Add(aTo[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";");
                            to_email += aTo[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";";
                        }
                    }
                }
                if(!string.IsNullOrEmpty(srSetting.EmailCc))
                {
                    aCc = srSetting.EmailCc.Split(Constants.SEPARATE_CC_LIST);
                    for (int i = 0; i < aCc.Count(); i++)
                    {
                        if (!duplicateEmail.Contains(aCc[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";") && !String.IsNullOrEmpty(aCc[i]))
                        {
                            duplicateEmail.Add(aCc[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";");
                            cc_email += aCc[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";";
                        }
                    }
                }
                if(!string.IsNullOrEmpty(srSetting.EmailBcc))
                {
                    aBcc = srSetting.EmailBcc.Split(Constants.SEPARATE_CC_LIST);
                    for (int i = 0; i < aBcc.Count(); i++)
                    {
                        if (!duplicateEmail.Contains(aBcc[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";") && !String.IsNullOrEmpty(aBcc[i]))
                        {
                            duplicateEmail.Add(aBcc[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";");
                            bcc_email += aBcc[i] + Constants.LOGIGEAR_EMAIL_DOMAIN + ";";
                        }
                    }
                }

            }
            #endregion
            if (!string.IsNullOrEmpty(to_email))
            {
                //WebUtils.SendMail(host, port, from_email, poster, to_email, cc_email, subject, body);
                WebUtils.SendMail(host, port, from_email, poster, to_email, cc_email, bcc_email, subject, body);
            }            
        }