public void SaveLiftingLimit(LiftingLimitDTO liftingLimitDetails)
        {
            liftinglimit liftinglimitEntity = new liftinglimit();
            AutoMapper.Mapper.Map(liftingLimitDetails, liftinglimitEntity);
            if (liftingLimitDetails.LiftingLimit_ID == 0)
            {
                using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.MaxValue))
                {
                    ESalesUnityContainer.Container.Resolve<IGenericRepository<liftinglimit>>().Save(liftinglimitEntity);
                    IList<LiftingLimitDTO> lifitinglimitActivelist = GetLimitList();
                    if (lifitinglimitActivelist.Count > 0)
                    {
                        foreach (LiftingLimitDTO liftinglimitdata in lifitinglimitActivelist)
                        {
                            if (liftinglimitdata.LiftingLimit_ID != liftinglimitEntity.LiftingLimit_ID && liftinglimitdata.LiftingLimit_BusinessTypeID == liftinglimitEntity.LiftingLimit_BusinessTypeID)
                            {
                                liftinglimit limitEntity = new liftinglimit();
                                liftinglimitdata.LiftingLimit_IsActive = false;
                                AutoMapper.Mapper.Map(liftinglimitdata, limitEntity);
                                ESalesUnityContainer.Container.Resolve<IGenericRepository<liftinglimit>>().TransactionalUpdate<liftinglimit>(limitEntity);
                            }
                        }
                        ESalesUnityContainer.Container.Resolve<IGenericRepository<liftinglimit>>().SaveChanges();
                    }

                    List<customermaterialmap> custmoerlist = ESalesUnityContainer.Container.Resolve<IGenericRepository<customermaterialmap>>()
                    .GetQuery().Where(data => data.customer.Cust_BusinessType == liftingLimitDetails.LiftingLimit_BusinessTypeID).ToList();

                    if (custmoerlist.Count > 0)
                    {
                        foreach (customermaterialmap customermaterialdata in custmoerlist)
                        {
                            customermaterialdata.Cust_Mat_LiftingLimit = liftingLimitDetails.LiftingLimit_Limit;
                            customermaterialdata.Cust_Mat_Timeinterval = liftingLimitDetails.LiftingLimit_Timeinterval;
                            ESalesUnityContainer.Container.Resolve<IGenericRepository<customermaterialmap>>().TransactionalUpdate<customermaterialmap>(customermaterialdata);
                        }
                        ESalesUnityContainer.Container.Resolve<IGenericRepository<customermaterialmap>>().SaveChanges();
                    }
                    ts.Complete();
                }
            }
        }
        public int UpdateLiftingLimit(LiftingLimitDTO liftingLimitDetails)
        {
            liftinglimit LiftingLimitEntity = new liftinglimit();
            liftinglimit_history LiftingLimithistoryEntity = new liftinglimit_history();
            int LiftingLimitid;
            
            using (TransactionScope transactionScope = new TransactionScope())
            {
                AutoMapper.Mapper.Map(liftingLimitDetails, LiftingLimitEntity);
                ESalesUnityContainer.Container.Resolve<IGenericRepository<liftinglimit>>().Update(LiftingLimitEntity);
                LiftingLimitid = liftingLimitDetails.LiftingLimit_ID;

                liftingLimitDetails.LiftingLimit_ID = 0;
                AutoMapper.Mapper.Map(liftingLimitDetails, LiftingLimithistoryEntity);
                ESalesUnityContainer.Container.Resolve<IGenericRepository<liftinglimit_history>>().Save(LiftingLimithistoryEntity);
                transactionScope.Complete();
            }
            return LiftingLimitid;
        }
 public LiftingLimitDTO GetLiftingLimitById(int liftingLimit_ID)
 {
     LiftingLimitDTO liftingLimitDetails = new LiftingLimitDTO();
     AutoMapper.Mapper.Map(ESalesUnityContainer.Container.Resolve<IGenericRepository<liftinglimit>>()
         .GetSingle(item => item.LiftingLimit_ID == liftingLimit_ID), liftingLimitDetails);
     liftingLimitDetails.truckregtype = null;
     return liftingLimitDetails;
 }
        public void DeleteLiftingLimit(int LiftingLimit_ID)
        {
            using (TransactionScope transactionScope = new TransactionScope())
            {
                LiftingLimitDTO liftingLimitDetails = new LiftingLimitDTO();
                liftingLimitDetails = ESalesUnityContainer.Container.Resolve<ILiftingLimit>()
                    .GetLiftingLimitById(LiftingLimit_ID);
                liftingLimitDetails.LiftingLimit_IsActive = false;
                UpdateLiftingLimit(liftingLimitDetails);

                transactionScope.Complete();
            }
        }
    protected void grdCustCautionLstMaster_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

        LiftingLimitDTO liftingLimitDetails = new LiftingLimitDTO();
        liftingLimitDetails = ESalesUnityContainer.Container.Resolve<ILiftingLimit>()
            .GetLiftingLimitById(Convert.ToInt32(grdCustCautionLstMaster.DataKeys[e.RowIndex].Value));

        liftingLimitDetails.Annual_LiftingLimit_Limit = Convert.ToInt32(((TextBox)grdCustCautionLstMaster.Rows[e.RowIndex].FindControl("txtBookingLimit")).Text);
        liftingLimitDetails.LiftingLimit_Business_Name = ((DropDownList)grdCustCautionLstMaster.Rows[e.RowIndex].FindControl("txtBusinessType")).SelectedItem.Text;
        liftingLimitDetails.LiftingLimit_BusinessTypeID = Convert.ToInt32(((DropDownList)grdCustCautionLstMaster.Rows[e.RowIndex].FindControl("txtBusinessType")).SelectedValue);
        liftingLimitDetails.LiftingLimit_LastUpdated = DateTime.Now;
        liftingLimitDetails.LiftingLimit_Limit = Convert.ToInt32(((DropDownList)grdCustCautionLstMaster.Rows[e.RowIndex].FindControl("ddlLiftingLimit")).SelectedValue);
        liftingLimitDetails.LiftingLimit_Timeinterval = Convert.ToInt32(((DropDownList)grdCustCautionLstMaster.Rows[e.RowIndex].FindControl("ddlTimeInterval")).SelectedValue);
        liftingLimitDetails.LiftingLimit_TruckRegType_Id = Convert.ToInt32(((DropDownList)grdCustCautionLstMaster.Rows[e.RowIndex].FindControl("ddlTruckType")).SelectedValue);
        liftingLimitDetails.LiftingLimit_TruckRegType_Name = ((DropDownList)grdCustCautionLstMaster.Rows[e.RowIndex].FindControl("ddlTruckType")).SelectedItem.Text;
        liftingLimitDetails.liftinginterval.liftinginterval_Id = Convert.ToInt32(((DropDownList)grdCustCautionLstMaster.Rows[e.RowIndex].FindControl("ddlLiftingLimit")).SelectedValue);
        //liftingLimitDetails.truckregtype.TruckRegType_IsDeleted = true;
        //liftingLimitDetails.truckregtype.TruckRegType_Id = Convert.ToInt32(((DropDownList)grdCustCautionLstMaster.Rows[e.RowIndex].FindControl("ddlTruckType")).SelectedValue);

        UpdateLiftingIntervalByBusinessTypeId(liftingLimitDetails.LiftingLimit_BusinessTypeID, liftingLimitDetails.Annual_LiftingLimit_Limit, liftingLimitDetails.LiftingLimit_Limit, liftingLimitDetails.LiftingLimit_Timeinterval, liftingLimitDetails.LiftingLimit_TruckRegType_Id);

        int liftingLimitId = ESalesUnityContainer.Container.Resolve<ILiftingLimit>().UpdateLiftingLimit(liftingLimitDetails);
        ucMessageBoxForGrid.ShowMessage("Lifting Details Saved Successfully");
    }
 protected void grdCustCautionLstMaster_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName.Equals(Globals.GridCommandEvents.ADDNEW))
     {
         if (Page.IsValid)
         {
             //To add customer in caution list 
             GridViewRow gvRow = (GridViewRow)((Button)e.CommandSource).NamingContainer;
             LiftingLimitDTO lifitinglimit = new LiftingLimitDTO();
             lifitinglimit.LifitingLimit_Date = DateTime.Now.Date;
             lifitinglimit.LiftingLimit_IsActive = true;
             lifitinglimit.LiftingLimit_CreatedDate = DateTime.Now;
             lifitinglimit.LiftingLimit_LastUpdated = DateTime.Now;
             lifitinglimit.LiftingLimit_CreatedBy = GetCurrentUserId();
             lifitinglimit.LiftingLimit_BusinessTypeID = Convert.ToInt32(((DropDownList)gvRow.FindControl("ddlBusinessType")).SelectedValue);
             lifitinglimit.LiftingLimit_TruckRegType_Id = Convert.ToInt32(((DropDownList)gvRow.FindControl("ddlTruckType")).SelectedValue);
             lifitinglimit.Annual_LiftingLimit_Limit = Convert.ToInt32(((TextBox)gvRow.FindControl("tbBookingLimit")).Text); ;
             lifitinglimit.LiftingLimit_Timeinterval = Convert.ToInt32(((DropDownList)gvRow.FindControl("ddlTimeInterval")).SelectedValue);
             lifitinglimit.LiftingLimit_Limit = Convert.ToInt32(((DropDownList)gvRow.FindControl("ddlLiftingLimit")).SelectedValue);
             lifitinglimit.LiftingLimit_IntervalId = Convert.ToInt32(((DropDownList)gvRow.FindControl("ddlTimeInterval")).SelectedValue);
             ESalesUnityContainer.Container.Resolve<ILiftingLimit>().SaveLiftingLimit(lifitinglimit);
             GetActivelimit();
             PopulateLiftingLimitHistory();
             ucMessageBoxForGrid.ShowMessage(Resources.Messages.Liftinglimitadd);
         }
     }
 }