/// <summary>
        /// Save the customer comment
        /// </summary>
        /// <param name="customerCommentVO">Value object of customer comment</param>
        public void SaveCustomerComment(CustomerCommentVO customerCommentVO)
        {
            if (customerCommentVO.CustomerCommentId == 0)
            {
                //Insert New Record
                CustomerComment newCustomerComment = new CustomerComment();
                newCustomerComment.CustomerID   = customerCommentVO.InvoiceCustomerId;
                newCustomerComment.OACustomer   = mdbDataContext.OACustomers.Where(c => c.ID == customerCommentVO.InvoiceCustomerId).SingleOrDefault();
                newCustomerComment.CustomerName = newCustomerComment.OACustomer.CustomerName;

                //newCustomerComment.CustomerName = customerCommentVO.InvoiceCustomerName;
                newCustomerComment.CompanyID    = customerCommentVO.CompanyId;
                newCustomerComment.Comment      = customerCommentVO.CustomerComment;
                newCustomerComment.Group        = customerCommentVO.Group;
                newCustomerComment.CreationDate = DateTime.Now;
                newCustomerComment.CreatedBy    = customerCommentVO.CreatedByUserId;
                mdbDataContext.CustomerComments.InsertOnSubmit(newCustomerComment);
                mdbDataContext.SubmitChanges();
            }
            else
            {
                //Update Existing Record
                CustomerComment selectedCustomerComment = mdbDataContext.CustomerComments.SingleOrDefault(c => c.ID == customerCommentVO.CustomerCommentId);
                selectedCustomerComment.CustomerID   = customerCommentVO.InvoiceCustomerId;
                selectedCustomerComment.OACustomer   = mdbDataContext.OACustomers.Where(c => c.ID == customerCommentVO.InvoiceCustomerId).SingleOrDefault();
                selectedCustomerComment.CustomerName = selectedCustomerComment.OACustomer.CustomerName;
                //selectedCustomerComment.CustomerName = customerCommentVO.InvoiceCustomerName;
                selectedCustomerComment.CompanyID       = customerCommentVO.CompanyId;
                selectedCustomerComment.Comment         = customerCommentVO.CustomerComment;
                selectedCustomerComment.Group           = customerCommentVO.Group;
                selectedCustomerComment.LastUpdatedDate = DateTime.Now;
                selectedCustomerComment.LastUpdatedBy   = customerCommentVO.LastUpdatedByUserId;
                mdbDataContext.SubmitChanges();
            }
        }
        /// <summary>
        /// Save the customerComment
        /// </summary>
        /// <param name="customerCommentVO">Value object of customer comment</param>
        public void SaveCustomerComment(CustomerCommentVO customerCommentVO)
        {
            CustomerCommentVO isCustomerCommentExist = null;

            isCustomerCommentExist = customerCommentDAL.GetCustomerCommentByName(String.Empty, customerCommentVO.CompanyId, customerCommentVO.InvoiceCustomerId);
            if (isCustomerCommentExist != null && customerCommentVO.CustomerCommentId != isCustomerCommentExist.CustomerCommentId)
            {
                throw new ApplicationException(String.Format(Constants.INVOICECUSTOMER_ALREADY_HAVE_COMMENT, customerCommentVO.InvoiceCustomerName));
            }

            else
            {
                customerCommentDAL.SaveCustomerComment(customerCommentVO);
            }

            //if (!string.IsNullOrEmpty(customerCommentVO.CustomerComment))
            //{
            //     isCustomerCommentExist = customerCommentDAL.GetCustomerCommentByName(customerCommentVO.CustomerComment, customerCommentVO.CompanyId, customerCommentVO.InvoiceCustomerId);

            //    //Check whether customercomment already exist or not
            //    if (isCustomerCommentExist != null && customerCommentVO.CustomerCommentId != isCustomerCommentExist.CustomerCommentId)
            //    {
            //        throw new ApplicationException(Constants.CUSTOMERCOMMENT_ALREADY_EXIST);
            //    }
            //    else
            //    {
            //        customerCommentDAL.SaveCustomerComment(customerCommentVO);
            //    }
            //}
        }
        /// <summary>
        /// Get check whether customer is grouped or not
        /// </summary>
        /// <param name="companyId">The company id</param>
        /// <param name="customerId">The customer id</param>
        /// <returns>value object of customer comment</returns>
        public CustomerCommentVO GetCustomerCommentByCompanyIdAndCustomerId(int companyId, int customerId)
        {
            CustomerComment customerComment = mdbDataContext.CustomerComments.FirstOrDefault(c => c.CompanyID == companyId &&
                                                                                             c.CustomerID == customerId &&
                                                                                             !c.IsDeleted);
            CustomerCommentVO customerCommentVO = customerComment != null ? new CustomerCommentVO(customerComment) : new CustomerCommentVO();

            return(customerCommentVO);
        }
        /// <summary>
        /// Gets customer comment details by Id
        /// </summary>
        /// <param name="customerCommentId">customerCommentId</param>
        /// <returns>Customer comment details</returns>
        public CustomerCommentVO GetCustomerCommentById(int customerCommentId)
        {
            CustomerComment customerComment = mdbDataContext.CustomerComments.SingleOrDefault(c => c.ID == customerCommentId);

            CustomerCommentVO customerCommentVO = null;

            if (customerComment != null)
            {
                customerCommentVO = new CustomerCommentVO(customerComment);
            }

            return(customerCommentVO);
        }
        /// <summary>
        /// Gets the Customer comment list
        /// </summary>
        /// <param name="companyId">company Id</param>
        /// <param name="invoiceCustomerId">invoiceCustomer Id</param>
        /// <returns>Customer commnet list</returns>
        private string GetCustomerComment(int companyId, int invoiceCustomerId)
        {
            MODEL.Contract contract = new MODEL.Contract();

            CustomerCommentService customerCommentService = new CustomerCommentService();
            CustomerCommentVO      customerCommentVO      = customerCommentService.GetCustomerCommentByCompanyAndCutomer(companyId, invoiceCustomerId);

            if (customerCommentVO != null)
            {
                contract.CustomerComment = customerCommentVO.CustomerComment;
            }

            return(contract.CustomerComment);
        }
 /// <summary>
 /// Transpose enduser value object to model object
 /// </summary>
 /// <param name="customerCommentVO">Value object of customerComment</param>
 public CustomerComment(CustomerCommentVO customerCommentVO)
 {
     ID = customerCommentVO.CustomerCommentId;
     InvoiceCustomerId   = customerCommentVO.InvoiceCustomerId;
     OldCustomerId       = customerCommentVO.OldCustomerId;
     InvoiceCustomerName = customerCommentVO.InvoiceCustomerName;
     InvoiceCustomer     = InvoiceCustomerName + '-' + OldCustomerId;
     CompanyId           = customerCommentVO.CompanyId;
     CompanyName         = customerCommentVO.CompanyName;
     Company             = customerCommentVO.CompanyName + '-' + customerCommentVO.CompanyId;
     //companyList = customerCommentVO.companyVOList
     Comment = customerCommentVO.CustomerComment;
     Group   = customerCommentVO.Group;
 }
        /// <summary>
        /// Check customer is grouped or not
        /// </summary>
        /// <param name="companyId">The company id</param>
        /// <param name="customerId">The customer id</param>
        /// <returns>Return true if customer is grouped, otherwise false</returns>
        private bool CheckCustomerGroupBy(int companyId, int customerId)
        {
            CustomerCommentDAL customerCommentDal = new CustomerCommentDAL();

            CustomerCommentVO customerCommentVO = customerCommentDal.GetCustomerCommentByCompanyIdAndCustomerId(companyId, customerId);

            bool isGrouped = false;

            //if customer found
            if (customerCommentVO != null)
            {
                isGrouped = customerCommentVO.Group;
            }

            return(isGrouped);
        }
        /// <summary>
        /// Transpose Model object to Value Object
        /// </summary>
        /// <param name="userId">user Id</param>
        /// <returns>Value object</returns>
        public CustomerCommentVO Transpose(int?userId)
        {
            CustomerCommentVO customerCommentVO = new CustomerCommentVO();

            customerCommentVO.CustomerCommentId   = this.ID;
            customerCommentVO.InvoiceCustomerId   = this.InvoiceCustomerId;
            customerCommentVO.OldCustomerId       = this.OldCustomerId;
            customerCommentVO.InvoiceCustomerName = this.InvoiceCustomerName;
            customerCommentVO.InvoiceCustomer     = this.InvoiceCustomerName + '-' + this.OldCustomerId;
            customerCommentVO.CompanyId           = this.CompanyId;
            customerCommentVO.CompanyName         = this.CompanyName;
            customerCommentVO.Company             = this.CompanyName + '-' + this.CompanyId;
            customerCommentVO.CustomerComment     = this.Comment;
            customerCommentVO.Group               = this.Group;
            customerCommentVO.CreatedByUserId     = userId;
            customerCommentVO.LastUpdatedByUserId = userId;

            return(customerCommentVO);
        }
        /// <summary>
        /// Gets the customer comment
        /// </summary>
        /// <param name="comment">comment</param>
        /// <param name="companyId">company Id</param>
        /// <param name="customerId">customer Id</param>
        /// <returns>customer comment</returns>
        public CustomerCommentVO GetCustomerCommentByName(string comment, int companyId, int customerId)
        {
            CustomerComment customercomment = null;

            if (!string.IsNullOrEmpty(comment))
            {
                customercomment = mdbDataContext.CustomerComments.Where(c => c.Comment.Equals(comment) && c.CompanyID == companyId && c.CustomerID == customerId && c.IsDeleted == false).SingleOrDefault();
            }
            else
            {
                customercomment = mdbDataContext.CustomerComments.Where(c => c.CompanyID == companyId && c.CustomerID == customerId && c.IsDeleted == false).SingleOrDefault();
            }

            CustomerCommentVO customerCommentVO = null;

            if (customercomment != null)
            {
                customerCommentVO = new CustomerCommentVO(customercomment);
            }

            return(customerCommentVO);
        }
        /// <summary>
        /// Save the customer comment
        /// </summary>
        /// <param name="model">model object</param>
        /// <returns></returns>
        public ActionResult CustomerCommentSave(MODEL.CustomerComment model)
        {
            try
            {
                bool ismodelValid = ModelState.IsValid;
                if (!ismodelValid)
                {
                    ismodelValid = IsModelValidForMultilineTextbox("Comment", model.Comment, 220);

                    if (ismodelValid)
                    {
                        model.Comment = model.Comment.Replace("\r\n", "\n");
                    }
                }

                if (ismodelValid)
                {
                    //Get user id
                    int?userId = Session.GetUserId();
                    CustomerCommentService customerCommentService = new CustomerCommentService();
                    //CustomerCommentVO customerCommentVO = new CustomerCommentVO(model, userId);

                    CustomerCommentVO customerCommentVO = model.Transpose(userId);

                    customerCommentService.SaveCustomerComment(customerCommentVO);
                    return(new HttpStatusCodeResult(200));
                }
                else
                {
                    throw new ApplicationException(String.Format(Constants.CANNOT_SAVE, Constants.CUSTOMERCOMMENT));
                }
            }
            catch (ApplicationException e)
            {
                return(new HttpStatusCodeAndErrorResult(500, e.Message));
            }
        }
        /// <summary>
        /// Edit customer comment
        /// </summary>
        /// <param name="id">The customer comment id</param>
        /// <returns>Customer comment details</returns>
        public ActionResult CustomerCommentEdit(int id)
        {
            MODEL.CustomerComment customercomment = new CustomerComment();
            try
            {
                CustomerCommentService customerCommentService = new CustomerCommentService();

                //Get Customercomment details
                CustomerCommentVO customerCommentVO = customerCommentService.GetCustomerCommentById(id);
                if (customerCommentVO == null)
                {
                    ModelState.AddModelError("", String.Format(Constants.ITEM_NOT_FOUND, Constants.CUSTOMERCOMMENT));
                }
                else
                {
                    customercomment = new CustomerComment(customerCommentVO);
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
            }
            return(PartialView("CustomerCommentDetails", customercomment));
        }