/// <summary>
        /// Save the Contract Line
        /// </summary>
        /// <param name="model">model object of Contract Line</param>
        /// <returns></returns>
        public ActionResult ContractLineSave(MODEL.ContractLine model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //Get user id
                    int?userId = Session.GetUserId();
                    ContractLineService contractLineService = new ContractLineService();
                    //ContractLineVO contractLineVO = new ContractLineVO(model, userId);

                    ContractLineVO contractLineVO = model.Transpose(userId);

                    contractLineService.ContractLineSave(contractLineVO);
                    return(new HttpStatusCodeResult(200));
                }
                else
                {
                    throw new ApplicationException(String.Format(Constants.CANNOT_SAVE, Constants.CONTRACT_LINE));
                }
            }
            catch (ApplicationException e)
            {
                return(new HttpStatusCodeAndErrorResult(500, e.Message));
            }
        }
        /// <summary>
        /// Edit ContractLine by id
        /// </summary>
        /// <param name="id">ContractLine Id</param>
        /// <returns>ContractLine details view</returns>
        public ActionResult ContractLineEdit(int id)
        {
            MODEL.ContractLine contractLine = new MODEL.ContractLine();;

            try
            {
                ContractLineService contractLineService = new ContractLineService();

                //Get contractLine details
                ContractLineVO contractLineVO = contractLineService.GetContractLineById(id);

                if (contractLineVO == null)
                {
                    ModelState.AddModelError("", String.Format(Constants.ITEM_NOT_FOUND, Constants.CONTRACT_LINE));
                }
                else
                {
                    contractLine = new MODEL.ContractLine(contractLineVO);
                    contractLine.CostCentreList       = GetCostCenterList(contractLineVO.Contract.CompanyID);
                    contractLine.ActivityCategoryList = GetActivityCategoryList();
                    contractLine.JobCodeList          = GetJobCodeList(contractLineVO.Contract.CompanyID, contractLineVO.Contract.InvoiceCustomerID);
                    contractLine.IsJobCodeExist       = IsJobCodeExist(contractLine.JobCodeList, contractLine.JobCodeId);
                    contractLine.ActivityCodeList     = GetActivityCodeList(contractLineVO.Contract.CompanyID);
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
            }
            return(PartialView("ContractLineDetails", contractLine));
        }
        /// <summary>
        /// Get the ActivityCode List
        /// </summary>
        /// <param name="companyId">company Id</param>
        /// <returns>ActivityCode List</returns>
        private List <MODEL.ActivityCode> GetActivityCodeList(int companyId)
        {
            MODEL.ContractLine    contractLine        = new MODEL.ContractLine();
            ActivityCodeService   activityCodeService = new ActivityCodeService();
            List <ActivityCodeVO> activityCodeVOList  = activityCodeService.GetActivityCodeList(companyId);

            foreach (ActivityCodeVO item in activityCodeVOList.FindAll(x => x.OAActivityCodeId.StartsWith("1")))
            {
                contractLine.ActivityCodeList.Add(new MODEL.ActivityCode(item));
            }

            return(contractLine.ActivityCodeList);
        }
        /// <summary>
        /// Gets the JobCode List
        /// </summary>
        /// <param name="companyId">company Id</param>
        /// <param name="CustomerId">customer Id</param>
        /// <returns>Jobcode list</returns>
        private List <MODEL.JobCode> GetJobCodeList(int?companyId, int customerId)
        {
            MODEL.ContractLine contractLine   = new MODEL.ContractLine();
            JobCodeService     jobCodeService = new JobCodeService();
            List <JobCodeVO>   jobCodeVOList  = jobCodeService.GetJobCodeList(companyId, customerId);

            foreach (JobCodeVO item in jobCodeVOList)
            {
                contractLine.JobCodeList.Add(new MODEL.JobCode(item));
            }

            return(contractLine.JobCodeList);
        }
        /// <summary>
        /// Gets the list of ActivityCategory
        /// </summary>
        /// <returns>ActivityCategory List</returns>
        private List <MODEL.ActivityCategory> GetActivityCategoryList()
        {
            MODEL.ContractLine        contractLine            = new MODEL.ContractLine();
            ActivityCategoryService   activityCategoryService = new ActivityCategoryService();
            List <ActivityCategoryVO> activityCategoryVOList  = activityCategoryService.GetActivityCategoryList();

            foreach (ActivityCategoryVO activityCategory in activityCategoryVOList)
            {
                contractLine.ActivityCategoryList.Add(new MODEL.ActivityCategory(activityCategory));
            }

            return(contractLine.ActivityCategoryList);
        }
        /// <summary>
        /// Gets the list of Costcenter based on Company Id
        /// </summary>
        /// <param name="companyId">Company Id</param>
        /// <returns>CostCentrer List</returns>
        private List <MODEL.CostCentre> GetCostCenterList(int?companyId)
        {
            MODEL.ContractLine  contractLine      = new MODEL.ContractLine();
            CostCenterService   costcenterService = new CostCenterService();
            List <CostCentreVO> costcenterVOList  = costcenterService.GetCostCenterList(companyId);

            foreach (CostCentreVO costcenter in costcenterVOList)
            {
                contractLine.CostCentreList.Add(new MODEL.CostCentre(costcenter));
            }

            return(contractLine.CostCentreList);
        }
        /// <summary>
        /// Create New Contract Line
        /// </summary>
        /// <param name="companyId">company id</param>
        /// <param name="customerId">customer id</param>
        /// <param name="contractId">contract id</param>
        /// <returns>ContractLine details view </returns>
        public ActionResult ContractLineCreate(int companyId, int customerId, int contractId)
        {
            try
            {
                MODEL.ContractLine contractLine = new MODEL.ContractLine();
                contractLine.CostCentreList       = GetCostCenterList(companyId);
                contractLine.ActivityCategoryList = GetActivityCategoryList();
                contractLine.ActivityCategoryId   = 21;
                contractLine.JobCodeList          = GetJobCodeList(companyId, customerId);
                contractLine.ContractID           = contractId;
                contractLine.ActivityCodeList     = GetActivityCodeList(companyId);

                return(PartialView("ContractLineDetails", contractLine));
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeAndErrorResult(500, e.Message));
            }
        }