/// <summary>
        /// Save and update agent details in database
        /// </summary>
        /// <param name="agentDetails">object containing agent details</param>
        public int SaveAndUpdateAgent(AgentDTO agentDetails)
        {            
            agentdetail agentEntity = new agentdetail();
            AutoMapper.Mapper.Map(agentDetails, agentEntity);

            if (agentEntity.Agent_Id > 0)
            {
                ESalesUnityContainer.Container.Resolve<IGenericRepository<agentdetail>>().Update(agentEntity);
            }
            else
            {
                //Save agent details
                ESalesUnityContainer.Container.Resolve<IGenericRepository<agentdetail>>().Save(agentEntity);

                //Gets list of materials from database
                IList<MaterialTypeDTO> listMaterial = ESalesUnityContainer.Container.Resolve<IMaterialTypeService>()
                    .GetMaterialTypeList(false);

                //Loops through list of materials and create mapping between agent and material
                foreach (var material in listMaterial)
                {                    
                    AgentMaterialPercentageDTO agentMaterialPercentageDetails = new AgentMaterialPercentageDTO();
                    agentMaterialPercentageDetails.AMP_Agent_Id = agentEntity.Agent_Id;
                    agentMaterialPercentageDetails.AMP_MaterialType_Id = material.MaterialType_Id;
                    agentMaterialPercentageDetails.AMP_IsActive = true;
                    agentMaterialPercentageDetails.AMP_CreatedBy = agentEntity.Agent_CreatedBy;
                    AgentMaterialPercentageService agentMatPercentageService = new AgentMaterialPercentageService();

                    //Save agent material mapping
                    agentMatPercentageService.SaveAgentMaterialPercentage(agentMaterialPercentageDetails);
                }
            }
            return agentEntity.Agent_Id;
        }
Exemple #2
0
     private void Fixupagentdetail(agentdetail previousValue)
     {
         if (previousValue != null && previousValue.bookings.Contains(this))
         {
             previousValue.bookings.Remove(this);
         }
 
         if (agentdetail != null)
         {
             if (!agentdetail.bookings.Contains(this))
             {
                 agentdetail.bookings.Add(this);
             }
             if (Booking_Agent_Id != agentdetail.Agent_Id)
             {
                 Booking_Agent_Id = agentdetail.Agent_Id;
             }
         }
         else if (!_settingFK)
         {
             Booking_Agent_Id = null;
         }
     }
     private void Fixupagentdetail(agentdetail previousValue)
     {
         if (previousValue != null && previousValue.agentmaterialpercentages.Contains(this))
         {
             previousValue.agentmaterialpercentages.Remove(this);
         }
 
         if (agentdetail != null)
         {
             if (!agentdetail.agentmaterialpercentages.Contains(this))
             {
                 agentdetail.agentmaterialpercentages.Add(this);
             }
             if (AMP_Agent_Id != agentdetail.Agent_Id)
             {
                 AMP_Agent_Id = agentdetail.Agent_Id;
             }
         }
     }
     private void Fixupagentdetail(agentdetail previousValue)
     {
         if (previousValue != null && previousValue.counterdetails.Contains(this))
         {
             previousValue.counterdetails.Remove(this);
         }
 
         if (agentdetail != null)
         {
             if (!agentdetail.counterdetails.Contains(this))
             {
                 agentdetail.counterdetails.Add(this);
             }
             if (CounterDetail_Agent_Id != agentdetail.Agent_Id)
             {
                 CounterDetail_Agent_Id = agentdetail.Agent_Id;
             }
         }
     }
        /// <summary>
        /// Delete agent details by agent Id
        /// </summary>
        /// <param name="agentID">Agent Id</param>
        public void DeleteAgent(int agentId)
        {
            using (TransactionScope transactionScope = new TransactionScope())
            {
                AgentMaterialPercentageService agentMatPercentageService = new AgentMaterialPercentageService();
                IList<AgentMaterialPercentageDTO> lstAgentMaterialPercentage = agentMatPercentageService.GetAgentMaterialPercentByAgentId(agentId);

                foreach (AgentMaterialPercentageDTO item in lstAgentMaterialPercentage)
                {
                    AgentMaterialPercentageDTO agentMaterialPercentage = agentMatPercentageService
                        .GetAgentMaterialPercentageByAMPId(item.AMP_Id);

                    agentMaterialPercentage.AMP_IsDeleted = true;
                    agentMatPercentageService.UpdateAgentPercentage(agentMaterialPercentage);
                }

                AgentDTO agentDetails = GetAgentByAgentId(agentId);
                agentDetails.Agent_IsDeleted = true;

                agentdetail agentEntity = new agentdetail();
                AutoMapper.Mapper.Map(agentDetails, agentEntity);

                ESalesUnityContainer.Container.Resolve<IGenericRepository<agentdetail>>().Update(agentEntity);
                //Commit transaction
                transactionScope.Complete();
            }
        }
     private void Fixupagentdetail(agentdetail previousValue)
     {
         if (previousValue != null && previousValue.useragentmappings.Contains(this))
         {
             previousValue.useragentmappings.Remove(this);
         }
 
         if (agentdetail != null)
         {
             if (!agentdetail.useragentmappings.Contains(this))
             {
                 agentdetail.useragentmappings.Add(this);
             }
             if (UAM_Agent_Id != agentdetail.Agent_Id)
             {
                 UAM_Agent_Id = agentdetail.Agent_Id;
             }
         }
     }
     private void Fixupagentdetail(agentdetail previousValue)
     {
         if (previousValue != null && previousValue.dcamaterialallocations.Contains(this))
         {
             previousValue.dcamaterialallocations.Remove(this);
         }
 
         if (agentdetail != null)
         {
             if (!agentdetail.dcamaterialallocations.Contains(this))
             {
                 agentdetail.dcamaterialallocations.Add(this);
             }
             if (DCAMA_Agent_Id != agentdetail.Agent_Id)
             {
                 DCAMA_Agent_Id = agentdetail.Agent_Id;
             }
         }
     }