public static void SendMail(TblApproverHeader ApproverHdr, RecommendRequestObj data, string ProcessType, string to)
        {
            try
            {
                using (var context = new SalesReturndbEntities())
                {
                    TblMailTemplate EmailTemplate = new TblMailTemplate();
                    string          subject       = string.Empty;

                    if (ProcessType == "reject")
                    {
                        if (data.Active_Role == 2)//ch
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 5).FirstOrDefault();
                        }
                        else if (data.Active_Role == 3)//cm
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 8).FirstOrDefault();
                        }
                        else if (data.Active_Role == 4)//lm
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 11).FirstOrDefault();
                        }
                        else if (data.Active_Role == 5)//ISC/Vp
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 14).FirstOrDefault();
                        }
                        else if (data.Active_Role == 8)//sh
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 21).FirstOrDefault();
                        }
                        else if (data.Active_Role == 7)//Regionl Head
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 18).FirstOrDefault();
                        }
                        else if (data.Active_Role == 5)//Vp Head
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 24).FirstOrDefault();
                        }
                        else if (data.Active_Role == 6)//President
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 27).FirstOrDefault();
                        }
                        //   subject = EmailTemplate.Subject.Replace("<RequestNo.>", "S" + "-" + data.Request_Id);
                    }
                    if (ProcessType == "reconsider")
                    {
                        if (data.Active_Role == 2) //ch
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 6).FirstOrDefault();
                        }
                        else if (data.Active_Role == 3) //cm
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 9).FirstOrDefault();
                        }
                        else if (data.Active_Role == 4) //lm
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 12).FirstOrDefault();
                        }
                        else if (data.Active_Role == 5) //isc Vp
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 15).FirstOrDefault();
                        }
                        else if (data.Active_Role == 7) //regional head
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 19).FirstOrDefault();
                        }
                        else if (data.Active_Role == 8) //Segment head
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 22).FirstOrDefault();
                        }
                        else if (data.Active_Role == 5) //isc Vp
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 25).FirstOrDefault();
                        }
                        else if (data.Active_Role == 6) //presdient
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 28).FirstOrDefault();
                        }
                        // subject = EmailTemplate.Subject.Replace("<RequestNo.>", "S" + "-" + data.Request_Id);
                    }

                    if (ProcessType == "recommended")
                    {
                        if (data.Active_Role == 2)
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 4).FirstOrDefault();
                        }
                        else if (data.Active_Role == 4)
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 10).FirstOrDefault();
                        }
                        else if (data.Active_Role == 7)
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 17).FirstOrDefault();
                        }

                        //subject = EmailTemplate.Subject.Replace("<RequestNo.>", data.Request_Id.ToString());
                    }
                    if (ProcessType == "approve")
                    {
                        if (data.Active_Role == 5)
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 13).FirstOrDefault();
                        }

                        else if (data.Active_Role == 3)//cm
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 7).FirstOrDefault();
                        }
                        else if (data.Active_Role == 7)//rh
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 26).FirstOrDefault();
                        }
                        else if (data.Active_Role == 9)//sh
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 20).FirstOrDefault();
                        }
                        else if (data.Active_Role == 6) //president
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 26).FirstOrDefault();
                        }
                        else if (data.Active_Role == 7) //RegionalHead
                        {
                            EmailTemplate = context.TblMailTemplates.Where(x => x.Id == 16).FirstOrDefault();
                        }
                        // subject = EmailTemplate.Subject.Replace("<RequestNo.>", data.Request_Id.ToString());
                    }
                    subject = EmailTemplate.Subject;
                    subject = GetSubject(subject, data);
                    string Body = GetHtml(EmailTemplate.MailBody, data);
                    //var CCMails = GetCC(data);
                    MailAddressCollection CCMails = new MailAddressCollection();
                    //CCMails.Add("*****@*****.**");
                    CCMails.Add("*****@*****.**");
                    int RequestType = data.RequestType_Id;
                    var UserDetail  = context.SP_LFGDetails(to).FirstOrDefault();
                    var FromEmail   = context.SP_LFGDetails(data.EmployeeCode).FirstOrDefault();
                    Body = Body.Replace("Requestor Name", FromEmail.Emp_First_name);
                    MailAddressCollection toMail   = new MailAddressCollection();
                    MailAddressCollection fromMail = new MailAddressCollection();
                    subject = subject.Replace("<EmployeeName>", FromEmail.Emp_First_name);
                    // toMail.Add(UserDetail.email_id);
                    // toMail.Add("*****@*****.**");
                    toMail.Add("*****@*****.**");

                    fromMail.Add(FromEmail.email_id);
                    Email.sendEmail(subject, "*****@*****.**", toMail, CCMails, Body);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        public static void UpdateRequestStatus(bool isNew, int Request_Id, string CreatedBy, string AssignedTo, int Active_Role, int Requested_Role, int CurrentStatus_Id, int FutureStatus_Id, string Remark)
        {
            using (var context = new SalesReturndbEntities())
            {
                using (TransactionScope T2 = new TransactionScope())
                {
                    int Approver_Id = 0;

                    if (isNew == true)
                    {
                        TblApproverHeader header = new TblApproverHeader()
                        {
                            Active_Role = Active_Role,
                            AssignedTo = AssignedTo,
                            Requested_Role = Requested_Role,
                            Request_Id = Request_Id ,
                            Status_Id = CurrentStatus_Id,
                            IsActive = true,
                            CreatedBy = CreatedBy,
                            CreatedDate = DateTime.Now,
                        };

                        context.Entry(header).State = EntityState.Added;
                        context.SaveChanges();

                        Approver_Id = header.Approver_Id;
                    }
                    else
                    {
                        var detail = context.TblApproverHeaders.Where(x => x.Request_Id == Request_Id).FirstOrDefault();

                        detail.Active_Role = Active_Role;
                        detail.AssignedTo = AssignedTo;
                        detail.Status_Id = CurrentStatus_Id;
                        detail.Requested_Role = Requested_Role;

                        detail.ModifiedBy = CreatedBy;
                        detail.ModifiedDate = DateTime.Now;
                        detail.IsActive = true;

                        context.Entry(detail).State = EntityState.Modified;
                        context.SaveChanges();

                        Approver_Id = detail.Approver_Id;
                    }

                    TblApproverDetail Appdetail = new TblApproverDetail()
                    {
                        Approver_Id = Approver_Id,
                        AssignedTo = AssignedTo,
                        Remark = Remark,
                        Role_Id = Active_Role,
                        Status_Id = CurrentStatus_Id,
                        CreatedBy = CreatedBy,
                        CreatedDate = DateTime.Now,
                        IsActive = true
                    };
                    context.Entry(Appdetail).State = EntityState.Added;
                    context.SaveChanges();

                    TblFutureStatu statu = new TblFutureStatu()
                    {
                        Request_ID = Request_Id,
                        EmployeeCode = AssignedTo,
                        Role = Requested_Role,
                        Status = FutureStatus_Id,
                        CreatedBy = CreatedBy,
                        CreatedDate = DateTime.Now,
                        IsActive = true
                    };

                    context.Entry(statu).State = EntityState.Added;
                    context.SaveChanges();

                    T2.Complete();
                    T2.Dispose();
                }
            }
        }