Example #1
0
        /// <summary>
        /// Esclates the request.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="web">The web.</param>
        /// <param name="item">The item.</param>
        /// <param name="mainListName">Name of the main list.</param>
        /// <param name="approverListName">Name of the approver list.</param>
        /// <returns>to users</returns>
        public static DataTable EsclateRequest(ClientContext context, Web web, ListItem item, string mainListName, string approverListName, DataTable tblEscalation, ref string toUser, int actionStatus)
        {
            try
            {
                DataRow dr      = tblEscalation.NewRow();
                string  userIDs = BELDataAccessLayer.GetEmailsFromPersonField(context, web, item["Approver"] as FieldUserValue[]);

                if (Convert.ToInt32(actionStatus) == 1)   //For Escalation Only
                {
                    string to = string.Empty;
                    foreach (string id in userIDs.Split(','))
                    {
                        UserDetails userDetail = BELDataAccessLayer.Instance.GetUserInformation(context, web, id);
                        if (userDetail != null)
                        {
                            to += "," + GetManagerEmail(context, web, userDetail.ReportingManager);
                            dr["UserFullName"] += userDetail.FullName + ", ";
                            dr["UserEmail"]    += userDetail.UserEmail + ", ";
                            dr["CCEmail"]      += userDetail.UserEmail + ",";
                        }
                    }
                    dr["ToEmail"]      = to.Trim(',');
                    dr["UserFullName"] = dr["UserFullName"].ToString().Trim(',');
                }
                else if (Convert.ToInt32(actionStatus) == 2) //For Reminder Only
                {
                    dr["UserEmail"]   = dr["ToEmail"] = BELDataAccessLayer.GetEmailUsingUserID(context, web, userIDs);
                    dr["PendingWith"] = dr["UserFullName"] = BELDataAccessLayer.GetNameUsingUserID(context, web, userIDs);
                }
                EmailHelper eHelper = new EmailHelper();/// Check if we can remove this.
                //List<ListItemDetail> listDetails = new List<ListItemDetail>();
                int      reqId    = (item["RequestID"] as FieldLookupValue).LookupId;
                List     mainList = web.Lists.GetByTitle(mainListName);
                ListItem mainItem = mainList.GetItemById(reqId);
                context.Load(mainItem);
                context.Load(mainList, m => m.DefaultDisplayFormUrl);
                context.ExecuteQuery();


                // dr["CCEmail"] = toUser;
                dr["EscOrReminder"]   = actionStatus;
                dr["ApplicationName"] = Convert.ToString(item["ApplicationName"]);
                dr["FormName"]        = Convert.ToString(item["FormName"]);
                // dr["ReferenceNo"] = (mainItem["DCRNo"] != null ? Convert.ToString(mainItem["DCRNo"]) : string.Empty);
                dr["RequestDate"] = (mainItem["RequestDate"] != null ? Convert.ToDateTime(mainItem["RequestDate"]).ToString("dd-MM-yyyy") : string.Empty);
                dr["AssignDate"]  = (item["AssignDate"] != null ? Convert.ToDateTime(item["AssignDate"]).ToLocalTime().ToString("dd-MM-yyyy") : string.Empty);
                //dr["BusinessUnit"] = (mainItem["BusinessUnit"] != null ? Convert.ToString(mainItem["BusinessUnit"]) : string.Empty);
                // dr["ProductName"] = (mainItem["ProductName"] != null ? Convert.ToString(mainItem["ProductName"]) : string.Empty);
                string link           = string.Empty;
                string referenceNo    = string.Empty;
                string emailSignature = string.Empty;
                link           = "#URL" + mainList.DefaultDisplayFormUrl + "?ID=" + mainItem["ID"];
                dr["ListName"] = mainListName;
                dr["ID"]       = mainItem.Id;
                if (mainListName == "DCR")
                {
                    referenceNo    = (mainItem["DCRNo"] != null ? Convert.ToString(mainItem["DCRNo"]) : string.Empty);
                    emailSignature = "DCRDCN Team";
                }
                else if (mainListName == "DCN")
                {
                    referenceNo    = (mainItem["DCNNo"] != null ? Convert.ToString(mainItem["DCNNo"]) : string.Empty);
                    emailSignature = "DCRDCN Team";
                }
                else if (mainListName == "NPD")
                {
                    referenceNo    = (mainItem["ProjectNo"] != null ? Convert.ToString(mainItem["ProjectNo"]) : string.Empty);
                    emailSignature = "NPD Team";
                }
                else if (mainListName == "Feedbacks")
                {
                    referenceNo    = (mainItem["FeedbackNo"] != null ? Convert.ToString(mainItem["FeedbackNo"]) : string.Empty);
                    emailSignature = "CC Department";
                }
                else if (mainListName == "ExistingArtwork")
                {
                    referenceNo    = (mainItem["ReferenceNo"] != null ? Convert.ToString(mainItem["ReferenceNo"]) : string.Empty);
                    emailSignature = "Artwork Team";
                }
                else if (mainListName == "NewArtwork")
                {
                    referenceNo    = (mainItem["ReferenceNo"] != null ? Convert.ToString(mainItem["ReferenceNo"]) : string.Empty);
                    emailSignature = "Artwork Team";
                }
                else if (mainListName == "ItemCodePreProcess")
                {
                    referenceNo    = (mainItem["Title"] != null ? Convert.ToString(mainItem["Title"]) : string.Empty);
                    emailSignature = "Item Code Document Management S​​ystem (SharePoint​)​​";
                }
                dr["Link"]           = link;
                dr["ReferenceNo"]    = referenceNo;
                dr["EmailSignature"] = emailSignature;
                dr["ActionStatus"]   = actionStatus;
                dr["DueDate"]        = (item["DueDate"] != null ? Convert.ToDateTime(item["DueDate"]).ToLocalTime().ToString("dd-MM-yyyy") : string.Empty);

                if (item["DueDate"] != null)
                {
                    dr["PendingSince"] = GetPendingDays(Convert.ToDateTime(item["DueDate"]));
                }
                else
                {
                    dr["PendingSince"] = "0";
                }
                string workflowstatus = Convert.ToString(mainItem["WorkflowStatus"]);
                if (!workflowstatus.Equals("Draft"))
                {
                    tblEscalation.Rows.Add(dr);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error Request Escalation: " + ex.Message);
                Console.Write(ex.StackTrace + "==>" + ex.Message);
                Logger.Error("Error Request Escalation: " + ex.Message);
            }
            return(tblEscalation);
        }
Example #2
0
        public ActionStatus SaveBySection(ISection sectionDetails, Dictionary <string, string> objDict)
        {
            lock (Padlock)
            {
                ActionStatus status       = new ActionStatus();
                DCRNoCount   currentDCRNo = null;
                //BELDataAccessLayer helper = new BELDataAccessLayer();
                if (sectionDetails != null && objDict != null)
                {
                    objDict[Parameter.ACTIVITYLOG]     = DCRDCNListNames.DCRACTIVITYLOG;
                    objDict[Parameter.APPLICATIONNAME] = ApplicationNameConstants.DCRAPP;
                    objDict[Parameter.FROMNAME]        = FormNameConstants.DCRFORM;
                    DCRDetailSection      section          = null;
                    DesignEngineerSection designEngSection = null;
                    if (sectionDetails.SectionName == DCRSectionName.DCRDETAILSECTION)
                    {
                        section = sectionDetails as DCRDetailSection;
                        if (string.IsNullOrEmpty(section.DCRNo) && sectionDetails.ActionStatus == ButtonActionStatus.SaveAsDraft)
                        {
                            section.Title = section.DCRNo = "View";
                        }
                        else if (sectionDetails.ActionStatus == ButtonActionStatus.NextApproval && (string.IsNullOrEmpty(section.DCRNo) || section.DCRNo == "View"))
                        {
                            ////section = sectionDetails as DCRDetailSection;
                            currentDCRNo        = GetDCRNo(section.BusinessUnit);
                            section.RequestDate = DateTime.Now;
                            if (currentDCRNo != null)
                            {
                                currentDCRNo.CurrentValue = currentDCRNo.CurrentValue + 1;
                                Logger.Info("DCR Current Value + 1 = " + currentDCRNo.CurrentValue);
                                section.DCRNo = string.Format("DCR-{0}-{1}-{2}", currentDCRNo.BusinessUnit, DateTime.Today.Year, string.Format("{0:0000}", currentDCRNo.CurrentValue));
                                section.Title = section.DCRNo;
                                Logger.Info("DCR No is " + section.DCRNo);
                                status.ExtraData = section.DCRNo;
                            }
                        }
                    }
                    if (sectionDetails.SectionName == DCRSectionName.DESIGNENGINEERSECTION && sectionDetails.ActionStatus == ButtonActionStatus.NextApproval)
                    {
                        designEngSection = sectionDetails as DesignEngineerSection;
                        if (designEngSection != null)
                        {
                            designEngSection.FinalDesignEngineer = objDict[Parameter.USEREID];
                        }
                    }
                    List <ListItemDetail> objSaveDetails = BELDataAccessLayer.Instance.SaveData(this.context, this.web, sectionDetails, objDict);
                    ListItemDetail        itemDetails    = objSaveDetails.Where(p => p.ListName.Equals(DCRDCNListNames.DCRLIST)).FirstOrDefault <ListItemDetail>();
                    if (sectionDetails.SectionName == DCRSectionName.DCRDETAILSECTION)
                    {
                        if (section != null && !string.IsNullOrEmpty(section.OldDCRNo))
                        {
                            Dictionary <string, dynamic> values = new Dictionary <string, dynamic>();
                            values.Add("IsDCRRetrieved", true);
                            BELDataAccessLayer.Instance.SaveFormFields(this.context, this.web, DCRDCNListNames.DCRLIST, section.OldDCRId, values);
                        }

                        if (itemDetails.ItemId > 0 && currentDCRNo != null)
                        {
                            //// AsyncHelper.Call(obj =>
                            ////  {
                            UpdateDCRNoCount(currentDCRNo);
                            Logger.Info("Update DCR No " + section.DCRNo);
                            ////  });
                        }
                    }

                    if (sectionDetails.SectionName == DCRSectionName.DESIGNENGINEERSECTION && sectionDetails.ActionStatus == ButtonActionStatus.NextApproval)
                    {
                        if (designEngSection != null && designEngSection.DateForCompletionOfTesting != null && designEngSection.DateForReceiptOfSamples != null)
                        {
                            EmailHelper eHelper = new EmailHelper();

                            Dictionary <string, string> mailCustomValues = null; List <FileDetails> emailAttachments = null;
                            Dictionary <string, string> email = new Dictionary <string, string>();
                            List <ListItemDetail>       itemdetail = new List <ListItemDetail>();
                            string applicationName = ApplicationNameConstants.DCRAPP; string formName = FormNameConstants.DCRFORM;

                            string from = string.Empty, to = string.Empty, cc = string.Empty, role = string.Empty, tmplName = string.Empty;
                            from = objDict[Parameter.USEREID];
                            from = BELDataAccessLayer.GetEmailUsingUserID(context, web, from);
                            to   = designEngSection.ProposedBy;
                            to   = BELDataAccessLayer.GetEmailUsingUserID(context, web, to);

                            cc       = from;
                            role     = DCRRoles.DESIGNENGINEER;
                            tmplName = EmailTemplateName.DESIGNENGGTOCREATOR;
                            itemdetail.Add(new ListItemDetail()
                            {
                                ItemId = itemDetails.ItemId, IsMainList = true, ListName = DCRDCNListNames.DCRLIST
                            });
                            if (mailCustomValues == null)
                            {
                                mailCustomValues = new Dictionary <string, string>();
                            }
                            mailCustomValues[Parameter.CURRENTAPPROVERNAME] = BELDataAccessLayer.GetNameUsingUserID(context, web, objDict[Parameter.USEREID]);

                            email = eHelper.GetEmailBody(context, web, tmplName, itemdetail, mailCustomValues, role, applicationName, formName);
                            eHelper.SendMail(applicationName, formName, tmplName, email["Subject"], email["Body"], from, to, cc, false, emailAttachments);
                        }
                    }

                    if (itemDetails.ItemId > 0)
                    {
                        status.IsSucceed = true;
                        status.ItemID    = itemDetails.ItemId;
                        switch (sectionDetails.ActionStatus)
                        {
                        case ButtonActionStatus.SaveAsDraft:
                            status.Messages.Add("Text_SaveDraftSuccess");
                            break;

                        case ButtonActionStatus.SaveAndNoStatusUpdate:
                            status.Messages.Add("Text_SaveSuccess");
                            break;

                        case ButtonActionStatus.NextApproval:
                            status.Messages.Add(ApplicationConstants.SUCCESSMESSAGE);
                            break;

                        case ButtonActionStatus.Delegate:
                            status.Messages.Add("Text_DelegatedSuccess");
                            break;

                        case ButtonActionStatus.Complete:
                            status.Messages.Add("Text_CompleteSuccess");
                            break;

                        case ButtonActionStatus.Rejected:
                            status.Messages.Add("Text_RejectedSuccess");
                            break;

                        default:
                            status.Messages.Add(ApplicationConstants.SUCCESSMESSAGE);
                            break;
                        }
                    }
                    else
                    {
                        status.IsSucceed = false;
                        status.Messages.Add(ApplicationConstants.ERRORMESSAGE);
                    }
                }
                return(status);
            }
        }