public Distributor MapDistributor(tblCostCentre tblCC)
      {
          if (tblCC == null) return null;
          var distributor = new Distributor(tblCC.Id) {CostCentreType = CostCentreType.Distributor};
          if (tblCC.tblRegion != null)
              distributor.Region = tblCC.tblRegion.Map();
          if (tblCC.Tier_Id != null)
              distributor.ProductPricingTier =
                  _ctx.tblPricingTier.FirstOrDefault(n => n.id == tblCC.Tier_Id).Map();
          distributor.CostCentreCode = tblCC.Cost_Centre_Code;
          if (tblCC.PaybillNumber != null)
              distributor.PaybillNumber = tblCC.PaybillNumber;
          if (tblCC.MerchantNumber != null)
              distributor.MerchantNumber = tblCC.MerchantNumber;

          return distributor;
      }
        private OutletDTO Map(tblCostCentre tbl)
        {
            var dto = new OutletDTO
                          {
                              MasterId = tbl.Id,
                              DateCreated = tbl.IM_DateCreated,
                              DateLastUpdated = tbl.IM_DateLastUpdated,
                              StatusId = tbl.IM_Status,
                              Name = tbl.Name,
                              CostCentreCode = tbl.Cost_Centre_Code,
                              ParentCostCentreId = tbl.ParentCostCentreId ?? Guid.Empty,
                              CostCentreTypeId = tbl.CostCentreType ?? 0,
                              RouteMasterId = tbl.RouteId ?? Guid.Empty,
                              OutletCategoryMasterId = tbl.Outlet_Category_Id ?? Guid.Empty,
                              OutletTypeMasterId = tbl.Outlet_Type_Id ?? Guid.Empty,
                              DiscountGroupMasterId = tbl.Outlet_DiscountGroupId ?? Guid.Empty,
                              OutletProductPricingTierMasterId = tbl.Tier_Id ?? Guid.Empty,
                              VatClassMasterId = tbl.VATClass_Id ?? Guid.Empty,
                              Latitude = tbl.StandardWH_Latitude,
                              Longitude = tbl.StandardWH_Longtitude,
                              IsApproved = tbl.IM_Status == (int)EntityStatus.Active,
                              ShippingAddresses = new List<ShipToAddressDTO>(),
                              SpecialPricingTierMasterId = tbl.SpecialPricingTierId ?? Guid.Empty,

                          };
            foreach (var item in tbl.tblShipToAddress.Where(n => n.IM_Status == (int)EntityStatus.Active))
            {
                var addressitem = new ShipToAddressDTO
                                      {
                                          OutletId = dto.MasterId,
                                          MasterId = item.Id,
                                          DateCreated = item.IM_DateCreated,
                                          DateLastUpdated = item.IM_DateLastUpdated,
                                          StatusId = item.IM_Status,
                                          Name = item.Name,
                                          Code = item.Code,
                                          Description = item.Description,
                                          PostalAddress = item.PostalAddress,
                                          PhysicalAddress = item.PhysicalAddress,
                                          Longitude = item.Longitude ?? 0,
                                          Latitude = item.Latitude ?? 0
                                      };
                dto.ShippingAddresses.Add(addressitem);
            }
            return dto;
        }
 private StoreDTO Map(tblCostCentre tbl)
 {
     var dto = new StoreDTO
     {
         MasterId = tbl.Id,
         DateCreated = tbl.IM_DateCreated,
         DateLastUpdated = tbl.IM_DateLastUpdated,
         StatusId = tbl.IM_Status,
         CostCentreCode = tbl.Cost_Centre_Code,
         Name = tbl.Name,
         ParentCostCentreId = tbl.ParentCostCentreId ?? Guid.Empty,
         CostCentreTypeId = tbl.CostCentreType ?? 0,
         Longitude = tbl.StandardWH_Longtitude,
         Latitude = tbl.StandardWH_Latitude,
         VatRegistrationNo = tbl.StandardWH_VatRegistrationNo
     };
     return dto;
 }
 private DistributorPendingDispatchWarehouseDTO Map(tblCostCentre tbl)
 {
     var dto = new DistributorPendingDispatchWarehouseDTO
                   {
                       MasterId = tbl.Id,
                       DateCreated = tbl.IM_DateCreated,
                       DateLastUpdated = tbl.IM_DateLastUpdated,
                       StatusId = tbl.IM_Status,
                       Name = tbl.Name,
                       CostCentreCode = tbl.Cost_Centre_Code,
                       ParentCostCentreId = tbl.ParentCostCentreId ?? Guid.Empty,
                       CostCentreTypeId = tbl.CostCentreType ?? 0,
                       VatRegistrationNo = tbl.StandardWH_VatRegistrationNo,
                       Longitude = tbl.StandardWH_Longtitude,
                       Latitude = tbl.StandardWH_Latitude
                   };
     return dto;
 }
 private DistributorSalesmanDTO Map(tblCostCentre tbl)
 {
     var dto = new DistributorSalesmanDTO
                   {
                       MasterId = tbl.Id,
                       DateCreated = tbl.IM_DateCreated,
                       DateLastUpdated = tbl.IM_DateLastUpdated,
                       StatusId = tbl.IM_Status,
                       Name = tbl.Name,
                       CostCentreCode = tbl.Cost_Centre_Code,
                       ParentCostCentreId = tbl.ParentCostCentreId ?? Guid.Empty,
                       CostCentreTypeId = tbl.CostCentreType ?? 0,
                       RouteMasterId = tbl.RouteId ?? Guid.Empty,
                       VatRegistrationNo = tbl.StandardWH_VatRegistrationNo,
                       Latitude = tbl.StandardWH_Latitude,
                       Longitude = tbl.StandardWH_Longtitude,
                       TypeId = tbl.CostCentreType2,
                   };
     return dto;
 }
 private CommoditySupplierDTO Map(tblCostCentre tbl)
 {
     var dto = new CommoditySupplierDTO
     {
         MasterId = tbl.Id,
         DateCreated = tbl.IM_DateCreated,
         DateLastUpdated = tbl.IM_DateLastUpdated,
         StatusId = tbl.IM_Status,
         Name = tbl.Name,
         CostCentreCode = tbl.Cost_Centre_Code,                
         ParentCostCentreId = tbl.ParentCostCentreId ?? Guid.Empty,
         CostCentreTypeId = tbl.CostCentreType ?? 0,
         CommoditySupplierTypeId = tbl.CostCentreType2,
         JoinDate = tbl.JoinDate ?? new DateTime(),
         AccountNo = tbl.AccountNumber,
         PinNo = tbl.Revenue_PIN,
         BankId = tbl.BankId.HasValue? tbl.BankId.Value:Guid.Empty,
         BankBranchId = tbl.BankBranchId.HasValue? tbl.BankBranchId.Value:Guid.Empty,
         AccountName=tbl.AccountName
     };
     return dto;
 }
        private ImportEntity Map(tblCostCentre item)
        {
            var result = new ImportEntity {MasterDataCollective = MasterDataCollective.Outlet.ToString()};
            result.Fields[0] = string.IsNullOrEmpty(item.Cost_Centre_Code)?"":item.Cost_Centre_Code.Trim();
            result.Fields[1] =string.IsNullOrEmpty(item.Name)?"":item.Name.Trim(); 
            result.Fields[2] = item.IM_Status == 1 ? true.ToString() : false.ToString();
            return result;

        }
 /// <summary>
 /// Deprecated Method for adding a new object to the tblCostCentre EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTotblCostCentre(tblCostCentre tblCostCentre)
 {
     base.AddObject("tblCostCentre", tblCostCentre);
 }
 /// <summary>
 /// Create a new tblCostCentre object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="iM_DateCreated">Initial value of the IM_DateCreated property.</param>
 /// <param name="iM_DateLastUpdated">Initial value of the IM_DateLastUpdated property.</param>
 /// <param name="iM_Status">Initial value of the IM_Status property.</param>
 /// <param name="costCentreType2">Initial value of the CostCentreType2 property.</param>
 public static tblCostCentre CreatetblCostCentre(global::System.Guid id, global::System.String name, global::System.DateTime iM_DateCreated, global::System.DateTime iM_DateLastUpdated, global::System.Int32 iM_Status, global::System.Int32 costCentreType2)
 {
     tblCostCentre tblCostCentre = new tblCostCentre();
     tblCostCentre.Id = id;
     tblCostCentre.Name = name;
     tblCostCentre.IM_DateCreated = iM_DateCreated;
     tblCostCentre.IM_DateLastUpdated = iM_DateLastUpdated;
     tblCostCentre.IM_Status = iM_Status;
     tblCostCentre.CostCentreType2 = costCentreType2;
     return tblCostCentre;
 }
 private DistributorDTO Map(tblCostCentre tbl)
 {
     var dto = new DistributorDTO
                   {
                       MasterId = tbl.Id,
                       DateCreated = tbl.IM_DateCreated,
                       DateLastUpdated = tbl.IM_DateLastUpdated,
                       StatusId = tbl.IM_Status,
                       Name = tbl.Name,
                       CostCentreCode = tbl.Cost_Centre_Code,
                       ParentCostCentreId = tbl.ParentCostCentreId ?? Guid.Empty,
                       CostCentreTypeId = tbl.CostCentreType ?? 0,
                       ProducerId = tbl.ParentCostCentreId ?? Guid.Empty,
                       Owner = tbl.Distributor_Owner,
                       PIN = tbl.Distributor_PIN,
                       AccountNo = tbl.Cost_Centre_Code,
                       RegionMasterId = tbl.Distributor_RegionId ?? Guid.Empty,
                       ASMUserMasterId = tbl.Distributor_ASM_Id,
                       SalesRepUserMasterId = tbl.SalesRep_Id,
                       SurveyorUserMasterId = tbl.Surveyor_Id,
                       ProductPricingTierMasterId = tbl.Tier_Id ?? Guid.Empty,
                       PaybillNumber = tbl.PaybillNumber,
                       MerchantNumber = tbl.MerchantNumber
                   };
     var asm = _context.tblUsers.FirstOrDefault(n => n.Id == dto.ASMUserMasterId);
     var salesRep = _context.tblUsers.FirstOrDefault(n => n.Id == dto.SalesRepUserMasterId);
     var surveyor = _context.tblUsers.FirstOrDefault(n => n.Id == dto.SurveyorUserMasterId);
     if (salesRep != null)
     {
         dto.SalesRepDTO = new UserDTO
                               {
                                   MasterId = salesRep.Id,
                                   DateCreated = salesRep.IM_DateCreated,
                                   DateLastUpdated = salesRep.IM_DateLastUpdated ?? DateTime.Now,
                                   StatusId = salesRep.IM_Status,
                                   Username = salesRep.UserName,
                                   CostCentre = salesRep.CostCenterId,
                                   Password = salesRep.Password,
                                   PIN = salesRep.PIN,
                                   UserTypeId = salesRep.UserType,
                                   Mobile = salesRep.Mobile,
                                   GroupMasterId = salesRep.GroupId ?? Guid.Empty,
                                   TillNumber = salesRep.TillNumber
                               };
     }
     if (asm != null)
     {
         dto.ASMDTO = new UserDTO
                               {
                                   MasterId = asm.Id,
                                   DateCreated = asm.IM_DateCreated,
                                   DateLastUpdated = asm.IM_DateLastUpdated ?? DateTime.Now,
                                   StatusId = asm.IM_Status,
                                   Username = asm.UserName,
                                   CostCentre = asm.CostCenterId,
                                   Password = asm.Password,
                                   PIN = asm.PIN,
                                   UserTypeId = asm.UserType,
                                   Mobile = asm.Mobile,
                                   GroupMasterId = asm.GroupId ?? Guid.Empty,
                                   TillNumber = asm.TillNumber
                               };
     }
     if (surveyor != null)
     {
         dto.SurveyorDTO = new UserDTO
         {
             MasterId = surveyor.Id,
             DateCreated = surveyor.IM_DateCreated,
             DateLastUpdated = surveyor.IM_DateLastUpdated ?? DateTime.Now,
             StatusId = surveyor.IM_Status,
             Username = surveyor.UserName,
             CostCentre = surveyor.CostCenterId,
             Password = surveyor.Password,
             PIN = surveyor.PIN,
             UserTypeId = surveyor.UserType,
             Mobile = surveyor.Mobile,
             GroupMasterId = surveyor.GroupId ?? Guid.Empty,
             TillNumber = surveyor.TillNumber
         };
     }
     return dto;
 }