public ClaimExpense Save(ClaimExpense expense)
        {
            if (expense.ClaimExpenseID == 0)
            {
                claimRulerDBContext.ClaimExpense.Add(expense);
            }

            claimRulerDBContext.SaveChanges();

            return(expense);
        }
        public ClaimExpense Get(int id)
        {
            ClaimExpense expense = null;

            expense = (from x in claimRulerDBContext.ClaimExpense
                       .Include("ExpenseType")
                       .Include("AdjusterMaster")
                       where x.ClaimExpenseID == id
                       select x
                       ).FirstOrDefault <ClaimExpense>();

            return(expense);
        }
        public async Task PostExtractData_ValidRequest_Success()
        {
            // Arrange
            var stubRequest = @"Please create an expense claim for the below. Relevant details are marked up as requested
                <expense>
                    <cost_centre>DEV002</cost_centre>
                    <total>1150.00</total>
                    <payment_method>personal card</payment_method>
                </expense>";

            var httpContext = new DefaultHttpContext();

            var stream = new MemoryStream(Encoding.UTF8.GetBytes(stubRequest));

            httpContext.Request.Body          = stream;
            httpContext.Request.ContentLength = stream.Length;

            var expectedResult = new ClaimExpense()
            {
                CostCentre    = "DEV002",
                TotalAmount   = 1150,
                PaymentMethod = "Credit Card"
            };

            _stubExtractorService = new Mock <IExtractorService>();
            _stubExtractorService.Setup(svc => svc.ExtractData(It.IsAny <string>())).Returns(expectedResult);

            _claimExpenseController = new ClaimExpenseController(_stubExtractorService.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = httpContext
                }
            };

            // Act
            var actionResult = await _claimExpenseController.Post();

            var resultStatus = ((ObjectResult)actionResult).StatusCode;
            var resultValue  = ((ObjectResult)actionResult).Value as ClaimExpense;

            // Assert
            Assert.IsNotNull(actionResult);
            Assert.AreEqual(expectedResult, resultValue);
            Assert.AreEqual((int)HttpStatusCode.OK, resultStatus);
        }
        public void Delete(int id)
        {
            // Create an entity to represent the Entity you wish to delete
            // Notice you don't need to know all the properties, in this
            // case just the ID will do.
            ClaimExpense expense = new ClaimExpense { ClaimExpenseID = id };

            // Now attach the category stub object to the "Categories" set.
            // This puts the Entity into the context in the unchanged state,
            // This is same state it would have had if you made the query
            DbContextHelper.DbContext.AttachTo("ClaimExpenses", expense);

            // Do the delete the category
            DbContextHelper.DbContext.ClaimExpense.Remove(expense);

            // Apply the delete to the database
            DbContextHelper.DbContext.SaveChanges();
        }
        public void Delete(int id)
        {
            // Create an entity to represent the Entity you wish to delete
            // Notice you don't need to know all the properties, in this
            // case just the ID will do.
            ClaimExpense expense = new ClaimExpense {
                ClaimExpenseID = id
            };

            // Now attach the category stub object to the "Categories" set.
            // This puts the Entity into the context in the unchanged state,
            // This is same state it would have had if you made the query
            DbContextHelper.DbContext.AttachTo("ClaimExpenses", expense);


            // Do the delete the category
            DbContextHelper.DbContext.ClaimExpense.Remove(expense);

            // Apply the delete to the database
            DbContextHelper.DbContext.SaveChanges();
        }
        protected void gvExpense_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            ClaimExpense claimExpense = null;
            int          claimID      = SessionHelper.getClaimID();
            int          id           = 0;

            if (e.CommandName == "DoEdit")
            {
                id = Convert.ToInt32(e.CommandArgument);

                using (ClaimExpenseManager repository = new ClaimExpenseManager()) {
                    claimExpense = repository.Get(id);
                }
                if (claimExpense != null)
                {
                    txtExpenseAmount.Value = claimExpense.ExpenseAmount;
                    txtExpenseQty.Value    = claimExpense.ExpenseQty;

                    if (claimExpense.ExpenseDate != null)
                    {
                        txtExpenseDate.Value = claimExpense.ExpenseDate;
                    }

                    txtExpenseDescription.Text   = claimExpense.ExpenseDescription;
                    cbxExpenseReimburse.Checked  = claimExpense.IsReimbursable;
                    ddlExpenseType.SelectedValue = claimExpense.ExpenseTypeID.ToString();
                    txtMyComments.Text           = claimExpense.InternalComments;
                    //cbIsBillable.Checked = claimExpense.IsBillable.Value;
                    //NEW OC 10/7/2014 // PUT IN PLACE TO GRAB THE NEW RATE IF USER HITS EDIT
                    ExpenseType expense   = null;
                    int         expenseID = 0;
                    if (ddlExpenseType.SelectedIndex > 0)
                    {
                        expenseID = Convert.ToInt32(ddlExpenseType.SelectedValue);

                        using (ExpenseTypeManager repository = new ExpenseTypeManager())
                        {
                            expense = repository.Get(expenseID);
                            if (expense != null)
                            {
                                txtExpenseAmount.Value = expense.ExpenseRate;
                                Session["multiplier"]  = expense.ExpenseRate;
                            }
                        }
                    }
                    // END NEW OC 10/7/2014

                    if (claimExpense.AdjusterID != null)
                    {
                        txtExpenseAdjuster.Text    = claimExpense.AdjusterMaster.adjusterName;
                        hf_expenseAdjusterID.Value = claimExpense.AdjusterMaster.AdjusterId.ToString();
                    }

                    showExpenseEditPanel();

                    ViewState["ClaimExpenseID"] = e.CommandArgument.ToString();
                }
            }
            else if (e.CommandName == "DoDelete")
            {
                id = Convert.ToInt32(e.CommandArgument);

                try {
                    using (ClaimExpenseManager repository = new ClaimExpenseManager()) {
                        repository.Delete(id);
                    }

                    // refresh grid
                    gvExpense.DataSource = loadExpenses(claimID);
                    gvExpense.DataBind();
                }
                catch (Exception ex) {
                    Core.EmailHelper.emailError(ex);

                    lblMessage.Text     = "Unable to delete claim expense.";
                    lblMessage.CssClass = "error";
                }
            }
        }
        //EMAIL TO: Specified User
        private void notifySpecifiedUser(AdjusterMaster adjuster, ClaimExpense claimExpense, Claim myClaim)
        {
            StringBuilder emailBody = new StringBuilder();
            string        password  = null;

            string[] recipients  = null;
            string   smtpHost    = null;
            int      smtpPort    = 0;
            string   siteUrl     = ConfigurationManager.AppSettings["siteUrl"].ToString();
            string   insuredName = Session["InsuredName"].ToString();
            string   subject     = "Claim # " + myClaim.InsurerClaimNumber + ", Please Read Claim Note, Claim Ruler Note for : " + insuredName;

            CRM.Data.Entities.SecUser user = null;

            string itsgHost          = ConfigurationManager.AppSettings["smtpHost"].ToString();
            string itsgHostPort      = ConfigurationManager.AppSettings["smtpPort"].ToString();
            string itsgEmail         = ConfigurationManager.AppSettings["smtpEmail"].ToString();
            string itsgEmailPassword = ConfigurationManager.AppSettings["smtpPassword"].ToString();

            string EmailExpense = ddlExpenseType.SelectedItem.Text;
            // string EmailActivity = ddlActivity.SelectedItem.Text;
            string EmailDescription = txtExpenseDescription.Text;
            string EmailInternal    = txtMyComments.Text;
            string EmailQuantity    = txtExpenseQty.Text;
            string EmailDate        = txtExpenseDate.Text;
            string userName         = SessionHelper.getUserName();
            string isReimburse      = null;
            string EmailAmount      = null;
            string EmailRate        = null;

            if (lblAmount.Visible == true)
            {
                EmailAmount = "$" + Session["EmailAmount"];
                //EmailRate = lblAmount.Text;
            }
            else
            {
                EmailAmount = txtExpenseAmount.Text;
                EmailRate   = "No rate specified";
            }

            bool reimburse = cbxExpenseReimburse.Checked;

            if (reimburse == true)
            {
                isReimburse = "Yes";
            }
            else
            {
                isReimburse = "No";
            }

            int.TryParse(itsgHostPort, out smtpPort);

            // get logged in user
            int userID = SessionHelper.getUserId();

            //Convert.ToInt32(itsgHostPort);
            // get current user email info
            user = SecUserManager.GetByUserId(userID);

            // load email credentials
            smtpHost = user.emailHost;
            int.TryParse(user.emailHostPort, out smtpPort);


            // recipients
            recipients = new string[] { txtEmailTo.Text };

            // build email body
            // .containerBox
            emailBody.Append("<div style=\"margin:auto;width:600px;border: 1px solid #DDDDE4; margin: auto;font-family: Tahoma, Arial,sans-serif;font-size: 12px;color: #808080;\">");

            // .header
            //emailBody.Append("<div style=\"background-image:url(https://appv3.claimruler.com/images/email_header_small.jpg);background-repeat: no-repeat;background-size: 100% 100%;height:70px;\"></div>");
            //emailBody.Append("<div><img src=\"http://app.claimruler.com/images/email_header_small.jpg\"></image></div>");

            // .paneContentInner
            emailBody.Append("<div style=\"margin: 20px;\">");
            emailBody.Append("Hi " + adjuster.adjusterName + ",<br><br>");
            emailBody.Append("The following activity was just logged on Claim # " + myClaim.InsurerClaimNumber + " for Insured: " + insuredName + "<br><br><br>");


            emailBody.Append("<table >");
            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>Expense:</b></td><td align=\"left\"> " + EmailExpense + "</td>");
            emailBody.Append("</tr>");
            // emailBody.Append("</table><br><br>");


            emailBody.Append("<tr>");
            emailBody.Append("<td align=\"left\"><b>Description:</b></td><td align=\"left\"> " + EmailDescription + "</td>");
            emailBody.Append("</tr>");


            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>Internal Comments:</b></td><td align=\"left\"> " + EmailInternal + "</td>");
            emailBody.Append("</tr>");

            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>Adjuster:</b></td><td align=\"left\"> " + adjuster.adjusterName + "</td>");
            emailBody.Append("</tr>");

            emailBody.Append("<tr></tr>");

            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>User Name:</b></td><td align=\"left\"> " + userName + "</td>");
            emailBody.Append("</tr>");

            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>Expense Date/Time:</b></td><td align=\"left\"> " + EmailDate + "</td>");
            emailBody.Append("</tr>");

            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>Reimburse?</b></td><td align=\"left\"> " + isReimburse + "</td>");
            emailBody.Append("</tr>");

            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>Quantity:</b></td><td align=\"left\"> " + EmailQuantity + "</td>");
            emailBody.Append("</tr>");


            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>Rate:</b></td><td align=\"left\"> " + EmailRate + "</td>");
            emailBody.Append("</tr>");

            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>Amount:</b></td><td align=\"left\"> " + EmailAmount + "</td>");
            emailBody.Append("</tr>");

            emailBody.Append("</table ><br><br>");

            emailBody.Append("</div>"); // inner containerBox
            emailBody.Append("</div>"); // paneContentInner
            emailBody.Append("</div>"); // containerBox

            //Core.EmailHelper.sendEmail(user.Email, recipients, null, "Claim Assignment Notification", emailBody.ToString(), null, user.emailHost, smtpPort, smtpEmail, smtpPassword, true);
            password = Core.SecurityManager.Decrypt(user.emailPassword);

            //Core.EmailHelper.sendEmail(user.Email, recipients, null, subject, emailBody.ToString(), null, user.emailHost, smtpPort, user.Email, password, user.isSSL ?? true);
            Core.EmailHelper.sendEmail(itsgEmail, recipients, null, subject, emailBody.ToString(), null, itsgHost, Convert.ToInt32(itsgHostPort), itsgEmail, itsgEmailPassword);
        }
        protected void btnSaveExpense_Click(object sender, EventArgs e)
        {
            Claim                 claim          = null;
            Claim                 myClaim        = null;
            ClaimExpense          claimExpense   = null;
            AdjusterMaster        adjuster       = null;
            CarrierInvoiceProfile CarrierInvoice = null;

            int clientID      = SessionHelper.getClientId();
            int userID        = SessionHelper.getUserId();
            int claimID       = SessionHelper.getClaimID();
            int myAdjusterID  = 0;
            int profileID     = 0;
            int expenseTypeID = 0;
            int id            = 0;


            Page.Validate("expense");
            if (!Page.IsValid)
            {
                return;
            }

            id = Convert.ToInt32(ViewState["ClaimExpenseID"]);

            ClaimManager cm = new ClaimManager();

            myClaim = cm.Get(claimID);

            try
            {
                expenseTypeID = Convert.ToInt32(ddlExpenseType.SelectedValue);

                using (TransactionScope scope = new TransactionScope())
                {
                    using (ClaimExpenseManager repository = new ClaimExpenseManager())
                    {
                        if (id == 0)
                        {
                            claimExpense         = new ClaimExpense();
                            claimExpense.ClaimID = claimID;
                        }
                        else
                        {
                            claimExpense = repository.Get(id);
                        }

                        // populate fields
                        if (txtExpenseAmount.Visible == false)
                        {
                            var x = Session["multiplier"].ToString();

                            double expenseAmount = Convert.ToDouble(x) * Convert.ToDouble(txtExpenseQty.ValueDecimal); //newOC 10/7/14
                            claimExpense.ExpenseAmount = Convert.ToDecimal(expenseAmount);

                            decimal d = Convert.ToDecimal(expenseAmount);
                            //Session["EmailAmount"] = "$" + Math.Round(d, 2);
                            Session["EmailAmount"] = String.Format("{0:0.00}", expenseAmount);
                            // Session["EmailAmount"] = expenseAmount;
                        }
                        else
                        {
                            claimExpense.ExpenseAmount = txtExpenseAmount.ValueDecimal;
                        }
                        claimExpense.ExpenseDate        = txtExpenseDate.Date;
                        claimExpense.ExpenseDescription = txtExpenseDescription.Text.Trim();
                        claimExpense.ExpenseTypeID      = expenseTypeID;
                        claimExpense.IsReimbursable     = cbxExpenseReimburse.Checked;
                        claimExpense.UserID             = userID;
                        claimExpense.AdjusterID         = Convert.ToInt32(hf_expenseAdjusterID.Value);
                        claimExpense.ExpenseQty         = txtExpenseQty.ValueDecimal;
                        claimExpense.InternalComments   = txtMyComments.Text.Trim();
                        claimExpense.Billed             = false;
                        // claimExpense.IsBillable = cbIsBillable.Checked;
                        // save expense
                        claimExpense = repository.Save(claimExpense);
                    }

                    // update diary entry
                    ClaimComment diary = new ClaimComment();
                    diary.ClaimID     = claimID;
                    diary.CommentDate = DateTime.Now;
                    diary.UserId      = userID;
                    diary.CommentText = string.Format("Expense: {0}, Description: {1}, Date: {2:MM/dd/yyyy}, Amount: {3:N2}, Adjuster: {4} Qty: {5:N2}",
                                                      ddlExpenseType.SelectedItem.Text,
                                                      claimExpense.ExpenseDescription,
                                                      claimExpense.ExpenseDate,
                                                      claimExpense.ExpenseAmount,
                                                      txtExpenseAdjuster.Text,
                                                      claimExpense.ExpenseQty
                                                      );
                    ClaimCommentManager.Save(diary);

                    // 2014-05-02 apply rule
                    using (SpecificExpenseTypePerCarrier ruleEngine = new SpecificExpenseTypePerCarrier())
                    {
                        claim         = new Claim();
                        claim.ClaimID = claimID;
                        RuleException ruleException = ruleEngine.TestRule(clientID, claim, expenseTypeID);

                        if (ruleException != null)
                        {
                            ruleException.UserID = Core.SessionHelper.getUserId();
                            ruleEngine.AddException(ruleException);
                            CheckSendMail(ruleException);
                        }
                    }
                    myAdjusterID = Convert.ToInt32(claimExpense.AdjusterID); //Convert.ToInt32(myClaim.AdjusterID);
                    //EMAIL ADJUSTER OC 10/22/2014
                    if (myAdjusterID != 0 || myAdjusterID != null)
                    {
                        adjuster = AdjusterManager.GetAdjusterId(myAdjusterID);
                    }
                    if (cbEmailAdjuster.Checked == true)
                    {
                        try
                        {
                            notifyAdjuster(adjuster, claimExpense, myClaim);
                        }
                        catch (Exception ex)
                        {
                            lblMessage.Text     = "Unable to send email to adjuster";
                            lblMessage.CssClass = "error";
                        }
                    }
                    //EMAIL CLIENT CONTACT OC 10/22/2014
                    if (cbEmailClient.Checked == true)              //Dont need to check if invoice Pro ID is empty becuase to get to this point, one has to exist already
                    {
                        if (Session["ComingFromAllClaims"] != null) //if the user got here straight from the all claims screen
                        {
                            profileID = Convert.ToInt32(Session["CarrierInvoiceID"]);
                        }
                        else//coming from claim detail page
                        {
                            profileID = Convert.ToInt32(Session["InvoiceProfileID"]);
                        }
                        CarrierInvoice = CarrierInvoiceProfileManager.Get(profileID);
                        try
                        {
                            notifyClientContact(CarrierInvoice, claimExpense, myClaim, adjuster);
                        }
                        catch (Exception ex)
                        {
                            lblMessage.Text     = "Unable to send email to client contact";
                            lblMessage.CssClass = "error";
                        }
                    }
                    //EMAIL TO WHOMEVER OC 10/22/2014
                    if (txtEmailTo.Text != "")
                    {
                        try
                        {
                            notifySpecifiedUser(adjuster, claimExpense, myClaim);
                        }
                        catch (Exception ex)
                        {
                            lblMessage.Text     = "Unable to send email to adjuster";
                            lblMessage.CssClass = "error";
                        }
                    }

                    // complete transaction
                    scope.Complete();
                }

                lblMessage.Text     = "Expense saved successfully.";
                lblMessage.CssClass = "ok";

                // refresh grid
                gvExpense.DataSource = loadExpenses(claimID);
                gvExpense.DataBind();

                // keep edit form active
                lbtnNewExpense_Click(null, null);
                lblAmount.Text           = "";
                lblAmount.Visible        = false;
                txtExpenseAmount.Visible = true;
            }
            catch (Exception ex) {
                Core.EmailHelper.emailError(ex);

                lblMessage.Text     = "Unable to save claim expense.";
                lblMessage.CssClass = "error";
            }
        }
        //EMAIL TO: Specified User
        private void notifySpecifiedUser(AdjusterMaster adjuster, ClaimExpense claimExpense, Claim myClaim)
        {
            StringBuilder emailBody = new StringBuilder();
            string password = null;
            string[] recipients = null;
            string smtpHost = null;
            int smtpPort = 0;
            string siteUrl = ConfigurationManager.AppSettings["siteUrl"].ToString();
            string insuredName = Session["InsuredName"].ToString();
            string subject = "Claim # " + myClaim.InsurerClaimNumber + ", Please Read Claim Note, Claim Ruler Note for : " + insuredName;
            CRM.Data.Entities.SecUser user = null;

            string itsgHost = ConfigurationManager.AppSettings["smtpHost"].ToString();
            string itsgHostPort = ConfigurationManager.AppSettings["smtpPort"].ToString();
            string itsgEmail = ConfigurationManager.AppSettings["smtpEmail"].ToString();
            string itsgEmailPassword = ConfigurationManager.AppSettings["smtpPassword"].ToString();

            string EmailExpense = ddlExpenseType.SelectedItem.Text;
            // string EmailActivity = ddlActivity.SelectedItem.Text;
            string EmailDescription = txtExpenseDescription.Text;
            string EmailInternal = txtMyComments.Text;
            string EmailQuantity = txtExpenseQty.Text;
            string EmailDate = txtExpenseDate.Text;
            string userName = SessionHelper.getUserName();
            string isReimburse = null;
            string EmailAmount = null;
            string EmailRate = null;
            if (lblAmount.Visible == true)
            {
                EmailAmount = "$" + Session["EmailAmount"];
                //EmailRate = lblAmount.Text;
            }
            else
            {
                EmailAmount = txtExpenseAmount.Text;
                EmailRate = "No rate specified";
            }

            bool reimburse = cbxExpenseReimburse.Checked;
            if (reimburse == true)
            {
                isReimburse = "Yes";
            }
            else
            {
                isReimburse = "No";
            }

            int.TryParse(itsgHostPort, out smtpPort);

            // get logged in user
            int userID = SessionHelper.getUserId();
            //Convert.ToInt32(itsgHostPort);
            // get current user email info
            user = SecUserManager.GetByUserId(userID);

            // load email credentials
            smtpHost = user.emailHost;
            int.TryParse(user.emailHostPort, out smtpPort);

            // recipients
            recipients = new string[] { txtEmailTo.Text };

            // build email body
            // .containerBox
            emailBody.Append("<div style=\"margin:auto;width:600px;border: 1px solid #DDDDE4; margin: auto;font-family: Tahoma, Arial,sans-serif;font-size: 12px;color: #808080;\">");

            // .header
            //emailBody.Append("<div style=\"background-image:url(https://appv3.claimruler.com/images/email_header_small.jpg);background-repeat: no-repeat;background-size: 100% 100%;height:70px;\"></div>");
            //emailBody.Append("<div><img src=\"http://app.claimruler.com/images/email_header_small.jpg\"></image></div>");

            // .paneContentInner
            emailBody.Append("<div style=\"margin: 20px;\">");
            emailBody.Append("Hi " + adjuster.adjusterName + ",<br><br>");
            emailBody.Append("The following activity was just logged on Claim # " + myClaim.InsurerClaimNumber + " for Insured: " + insuredName + "<br><br><br>");

            emailBody.Append("<table >");
            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>Expense:</b></td><td align=\"left\"> " + EmailExpense + "</td>");
            emailBody.Append("</tr>");
            // emailBody.Append("</table><br><br>");

            emailBody.Append("<tr>");
            emailBody.Append("<td align=\"left\"><b>Description:</b></td><td align=\"left\"> " + EmailDescription + "</td>");
            emailBody.Append("</tr>");

            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>Internal Comments:</b></td><td align=\"left\"> " + EmailInternal + "</td>");
            emailBody.Append("</tr>");

            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>Adjuster:</b></td><td align=\"left\"> " + adjuster.adjusterName + "</td>");
            emailBody.Append("</tr>");

            emailBody.Append("<tr></tr>");

            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>User Name:</b></td><td align=\"left\"> " + userName + "</td>");
            emailBody.Append("</tr>");

            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>Expense Date/Time:</b></td><td align=\"left\"> " + EmailDate + "</td>");
            emailBody.Append("</tr>");

            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>Reimburse?</b></td><td align=\"left\"> " + isReimburse + "</td>");
            emailBody.Append("</tr>");

            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>Quantity:</b></td><td align=\"left\"> " + EmailQuantity + "</td>");
            emailBody.Append("</tr>");

            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>Rate:</b></td><td align=\"left\"> " + EmailRate + "</td>");
            emailBody.Append("</tr>");

            emailBody.Append("<tr> ");
            emailBody.Append("<td align=\"left\"><b>Amount:</b></td><td align=\"left\"> " + EmailAmount + "</td>");
            emailBody.Append("</tr>");

            emailBody.Append("</table ><br><br>");

            emailBody.Append("</div>");	// inner containerBox
            emailBody.Append("</div>");	// paneContentInner
            emailBody.Append("</div>");	// containerBox

            //Core.EmailHelper.sendEmail(user.Email, recipients, null, "Claim Assignment Notification", emailBody.ToString(), null, user.emailHost, smtpPort, smtpEmail, smtpPassword, true);
            password = Core.SecurityManager.Decrypt(user.emailPassword);

            //Core.EmailHelper.sendEmail(user.Email, recipients, null, subject, emailBody.ToString(), null, user.emailHost, smtpPort, user.Email, password, user.isSSL ?? true);
            Core.EmailHelper.sendEmail(itsgEmail, recipients, null, subject, emailBody.ToString(), null, itsgHost, Convert.ToInt32(itsgHostPort), itsgEmail, itsgEmailPassword);
        }
        protected void btnSaveExpense_Click(object sender, EventArgs e)
        {
            Claim claim = null;
            Claim myClaim = null;
            ClaimExpense claimExpense = null;
            AdjusterMaster adjuster = null;
            CarrierInvoiceProfile CarrierInvoice = null;

            int clientID = SessionHelper.getClientId();
            int userID = SessionHelper.getUserId();
            int claimID = SessionHelper.getClaimID();
            int myAdjusterID = 0;
            int profileID = 0;
            int expenseTypeID = 0;
            int id = 0;

            Page.Validate("expense");
            if (!Page.IsValid)
                return;

            id = Convert.ToInt32(ViewState["ClaimExpenseID"]);

            ClaimManager cm = new ClaimManager();
            myClaim = cm.Get(claimID);

            try
            {
                expenseTypeID = Convert.ToInt32(ddlExpenseType.SelectedValue);

                using (TransactionScope scope = new TransactionScope())
                {
                    using (ClaimExpenseManager repository = new ClaimExpenseManager())
                    {
                        if (id == 0) {
                            claimExpense = new ClaimExpense();
                            claimExpense.ClaimID = claimID;
                        }
                        else {
                            claimExpense = repository.Get(id);
                        }

                        // populate fields
                        if(txtExpenseAmount.Visible == false)
                        {
                            var x = Session["multiplier"].ToString();

                            double expenseAmount = Convert.ToDouble(x) * Convert.ToDouble(txtExpenseQty.ValueDecimal); //newOC 10/7/14
                            claimExpense.ExpenseAmount = Convert.ToDecimal(expenseAmount);

                            decimal d = Convert.ToDecimal(expenseAmount);
                            //Session["EmailAmount"] = "$" + Math.Round(d, 2);
                            Session["EmailAmount"] = String.Format("{0:0.00}", expenseAmount);
                           // Session["EmailAmount"] = expenseAmount;
                        }
                        else
                        {
                            claimExpense.ExpenseAmount = txtExpenseAmount.ValueDecimal;
                        }
                        claimExpense.ExpenseDate = txtExpenseDate.Date;
                        claimExpense.ExpenseDescription = txtExpenseDescription.Text.Trim();
                        claimExpense.ExpenseTypeID = expenseTypeID;
                        claimExpense.IsReimbursable = cbxExpenseReimburse.Checked;
                        claimExpense.UserID = userID;
                        claimExpense.AdjusterID = Convert.ToInt32(hf_expenseAdjusterID.Value);
                        claimExpense.ExpenseQty = txtExpenseQty.ValueDecimal;
                        claimExpense.InternalComments = txtMyComments.Text.Trim();
                        claimExpense.Billed = false;
                       // claimExpense.IsBillable = cbIsBillable.Checked;
                        // save expense
                        claimExpense = repository.Save(claimExpense);
                    }

                    // update diary entry
                    ClaimComment diary = new ClaimComment();
                    diary.ClaimID = claimID;
                    diary.CommentDate = DateTime.Now;
                    diary.UserId = userID;
                    diary.CommentText = string.Format("Expense: {0}, Description: {1}, Date: {2:MM/dd/yyyy}, Amount: {3:N2}, Adjuster: {4} Qty: {5:N2}",
                                                ddlExpenseType.SelectedItem.Text,
                                                claimExpense.ExpenseDescription,
                                                claimExpense.ExpenseDate,
                                                claimExpense.ExpenseAmount,
                                                txtExpenseAdjuster.Text,
                                                claimExpense.ExpenseQty
                                                );
                    ClaimCommentManager.Save(diary);

                    // 2014-05-02 apply rule
                    using (SpecificExpenseTypePerCarrier ruleEngine = new SpecificExpenseTypePerCarrier())
                    {
                        claim = new Claim();
                        claim.ClaimID = claimID;
                        RuleException ruleException = ruleEngine.TestRule(clientID, claim, expenseTypeID);

                        if (ruleException != null) {
                            ruleException.UserID = Core.SessionHelper.getUserId();
                            ruleEngine.AddException(ruleException);
                            CheckSendMail(ruleException);
                        }
                    }
                    myAdjusterID = Convert.ToInt32(claimExpense.AdjusterID); //Convert.ToInt32(myClaim.AdjusterID);
                    //EMAIL ADJUSTER OC 10/22/2014
                    if (myAdjusterID != 0 || myAdjusterID != null)
                    {
                        adjuster = AdjusterManager.GetAdjusterId(myAdjusterID);
                    }
                    if (cbEmailAdjuster.Checked == true)
                    {
                        try
                        {
                            notifyAdjuster(adjuster, claimExpense, myClaim);

                        }
                        catch (Exception ex)
                        {
                            lblMessage.Text = "Unable to send email to adjuster";
                            lblMessage.CssClass = "error";
                        }
                    }
                    //EMAIL CLIENT CONTACT OC 10/22/2014
                    if (cbEmailClient.Checked == true) //Dont need to check if invoice Pro ID is empty becuase to get to this point, one has to exist already
                    {
                        if (Session["ComingFromAllClaims"] != null) //if the user got here straight from the all claims screen
                        {
                            profileID = Convert.ToInt32(Session["CarrierInvoiceID"]);
                        }
                        else//coming from claim detail page
                        {
                            profileID = Convert.ToInt32(Session["InvoiceProfileID"]);
                        }
                        CarrierInvoice = CarrierInvoiceProfileManager.Get(profileID);
                        try
                        {
                              notifyClientContact(CarrierInvoice, claimExpense, myClaim, adjuster);
                        }
                        catch (Exception ex)
                        {
                            lblMessage.Text = "Unable to send email to client contact";
                            lblMessage.CssClass = "error";
                        }

                    }
                    //EMAIL TO WHOMEVER OC 10/22/2014
                    if (txtEmailTo.Text != "")
                    {

                        try
                        {
                             notifySpecifiedUser(adjuster, claimExpense, myClaim);
                        }
                        catch (Exception ex)
                        {
                            lblMessage.Text = "Unable to send email to adjuster";
                            lblMessage.CssClass = "error";
                        }
                    }

                    // complete transaction
                    scope.Complete();
                }

                lblMessage.Text = "Expense saved successfully.";
                lblMessage.CssClass = "ok";

                // refresh grid
                gvExpense.DataSource = loadExpenses(claimID);
                gvExpense.DataBind();

                // keep edit form active
                lbtnNewExpense_Click(null, null);
                lblAmount.Text = "";
                lblAmount.Visible = false;
                txtExpenseAmount.Visible = true;
            }
            catch (Exception ex) {
                Core.EmailHelper.emailError(ex);

                lblMessage.Text = "Unable to save claim expense.";
                lblMessage.CssClass = "error";
            }
        }
        public static string SaveClaimExpense(string expenseType, string insurerClaimId, string insurerName, int claimAdjusterId, string adjusterComapnyName, string updatedby, string commentNote, string emailTo, int carrierID, int claimID, string recipientId, string claimAdjuster, string expenseTypeName, string carrier, string idOf, string expenseQty, string expenseAmount, string expenseDate, string reimbrance)
        {
            string json = "";
            Claim objclaim = null;
            AdjusterMaster objAdjusterMaster = null;
            Leads objLeads = null;
            ClaimComment comment = null;
            ClaimExpense claimExpense = null;
            CRM.Data.Entities.LeadPolicy objLeadPolicy = null;
            int userID = SessionHelper.getUserId();
            int leadID = 0;
            int policyId = 0;
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    using (ClaimManager repository = new ClaimManager())
                    {
                        objclaim = new Claim();
                        objclaim.ClaimID = claimID;

                        objclaim.InsurerClaimNumber = insurerClaimId;
                        //objclaim.CarrierID = carrierID;
                        objclaim.AdjusterID = claimAdjusterId;
                        // objclaim.StatusUpdatedBy = updatedby;
                        repository.UpdateClaimStatus(objclaim);

                        // AdjusterMaster
                        objAdjusterMaster = new AdjusterMaster();
                        objAdjusterMaster.AdjusterId = claimAdjusterId;
                        //objAdjusterMaster.CompanyName = AdjusterComapnyName;
                        repository.UpdateAdjusterName(objAdjusterMaster);

                        //leads
                        leadID = repository.GetPolicyId(claimID);
                        objLeads = new Leads();
                        objLeads.LeadId = leadID;
                        objLeads.InsuredName = insurerName;
                        repository.UpdateInsurerName(objLeads);
                        //save carrier id in Lead policy
                        policyId = repository.GetLeadPolicyId(claimID);
                        objLeadPolicy = new Data.Entities.LeadPolicy();
                        objLeadPolicy.Id = policyId;
                        objLeadPolicy.CarrierID = carrierID;
                        repository.UpdateCarrierId(objLeadPolicy);

                        //add expense
                        ClaimExpenseManager objClaimExpenseManager = new ClaimExpenseManager();
                        claimExpense = new ClaimExpense();
                        claimExpense.ClaimID = claimID;
                        if (!string.IsNullOrEmpty(expenseAmount))
                        {
                            claimExpense.ExpenseAmount = Convert.ToDecimal(expenseAmount);
                        }
                        if (!string.IsNullOrEmpty(expenseDate))
                        {
                            claimExpense.ExpenseDate = Convert.ToDateTime(expenseDate);
                        }
                        claimExpense.ExpenseDescription = commentNote.Trim();
                        claimExpense.ExpenseTypeID = Convert.ToInt32(expenseType);
                        if (reimbrance == "1")
                        {
                            claimExpense.IsReimbursable = true;
                        }
                        else
                        {
                            claimExpense.IsReimbursable = false;
                        }

                        claimExpense.UserID = userID;
                        claimExpense.AdjusterID = Convert.ToInt32(claimAdjusterId);
                        if (!string.IsNullOrEmpty(expenseQty))
                        {
                            claimExpense.ExpenseQty = Convert.ToDecimal(expenseQty);
                        }
                        objClaimExpenseManager.Save(claimExpense);

                        //claim comment for add notes
                        comment = new ClaimComment();
                        comment.ClaimID = claimID;
                        comment.IsActive = true;
                        comment.UserId = Core.SessionHelper.getUserId();
                        comment.CommentDate = DateTime.Now;
                        comment.ActivityType = "Add Expense";
                        comment.CommentText = string.Format("Expense: {0}, Description: {1}, Date: {2:MM/dd/yyyy}, Amount: {3:N2}, Adjuster: {4} Qty: {5:N2}",
                                                 expenseTypeName,
                                                 commentNote.Trim(),
                                                 Convert.ToDateTime(expenseDate),
                                                 expenseAmount,
                                                 claimAdjuster,
                                                 expenseQty
                                                 );
                        ClaimCommentManager.Save(comment);

                    }
                    scope.Complete();
                }
                string[] recipId = recipientId.Split(',');
                string recipientEmailId = string.Empty;

                string[] IdofTable = idOf.Split(',');
                int index2 = 0;
                for (int index = 0; index < recipId.Length; index++)
                {
                    index2 = 0;
                    int.TryParse(recipId[index], out index2);
                    if (IdofTable[index] == "c")
                    {

                        Contact objContact = ContactManager.Get(index2);
                        if (!string.IsNullOrEmpty(objContact.Email))
                        {
                            if (recipientEmailId == "")
                            {
                                recipientEmailId = objContact.Email;
                            }
                            else
                            {
                                recipientEmailId = recipientEmailId + "," + objContact.Email;
                            }
                        }
                    }
                    else
                    {

                        AdjusterMaster objAdjuster = AdjusterManager.GetAdjusterId(index2);

                        if (!string.IsNullOrEmpty(objAdjuster.email))
                        {
                            if (recipientEmailId == "")
                            {
                                recipientEmailId = objAdjuster.email;
                            }
                            else
                            {
                                recipientEmailId = recipientEmailId + "," + objAdjuster.email;
                            }
                        }

                    }
                }
                SendExpenseEmail(expenseType, insurerClaimId, insurerName, claimAdjusterId, adjusterComapnyName, updatedby, commentNote, "", carrierID, claimID, recipientEmailId, claimAdjuster, expenseTypeName, carrier, recipId, IdofTable, expenseQty, expenseAmount, expenseDate, reimbrance);
                json = "Expense add successfully";

            }
            catch (Exception ex)
            {
                Core.EmailHelper.emailError(ex);
            }

            return json;
        }
        public ClaimExpense Save(ClaimExpense expense)
        {
            if (expense.ClaimExpenseID == 0)
                claimRulerDBContext.ClaimExpense.Add(expense);

            claimRulerDBContext.SaveChanges();

            return expense;
        }