/// <summary>
 /// Saves/Updates master configuration
 /// </summary>
 /// <param name="masterConfigDto"></param>
 /// <returns>int</returns>
 public int SaveMasterConfiguration(tblMasterConfigurationDto masterConfigDto)
 {
     Mapper.CreateMap<tblMasterConfigurationDto, tblMasterConfig>();
     int result = 0;
     try
     {
         using (var masterConfigContext = new FPConfigEntities())
         {
             var masterConfig = new tblMasterConfig();
             //Update mode
             if (masterConfigDto.Id > 0)
             {
                 masterConfig = masterConfigContext.tblMasterConfigs.Find(masterConfigDto.Id);
                 Mapper.Map(masterConfigDto, masterConfig);
                 result = masterConfigContext.SaveChanges();
             }
             //New configuration
             else
             {
                 Mapper.Map(masterConfigDto, masterConfig);
                 masterConfigContext.tblMasterConfigs.Add(masterConfig);
                 result = masterConfigContext.SaveChanges();
             }
         }
     }
     catch
     {
         return -1;
     }
     return result;
 }
        /// <summary>
        /// Saves email log and remove email queue
        /// </summary>
        /// <param name="masterConfigDto"></param>
        /// <returns>int</returns>
        public int SaveEmailLog(tblEmailLogDto emailLogDto, int emailQueueId)
        {
            Mapper.CreateMap<tblEmailLogDto, tblEmailLog>();
            int result = 0;
            try
            {
                using (var fpCofigDataContext = new FPConfigEntities())
                {
                    // save email log
                    var emailLog = new tblEmailLog();
                    Mapper.Map(emailLogDto, emailLog);
                    fpCofigDataContext.tblEmailLogs.Add(emailLog);

                    // remove email queue
                    var emailQueue = fpCofigDataContext.tblEmailQueues.Find(emailQueueId);
                    fpCofigDataContext.tblEmailQueues.Remove(emailQueue);

                    //save transaction
                    result = fpCofigDataContext.SaveChanges();
                }
            }
            catch
            {
                return -1;
            }
            return result;
        }
        /// <summary>
        /// Save Page Specific Placeholder
        /// </summary>
        /// <param name="tblPageSpecificPlaceholderConfigDto"></param>
        /// <returns></returns>
        public int SavePageSpecificPlaceholder(tblPageSpecificPlaceholderConfigDto tblPageSpecificPlaceholderConfigDto)
        {
            using (var fpCofigDataContext = new FPConfigEntities())
            {
                int result = 0;

                Mapper.CreateMap<tblPageSpecificPlaceholderConfigDto, tblPageSpecificPlaceholderConfig>();

                //update
                if (tblPageSpecificPlaceholderConfigDto.Id > 0)
                {
                    var tblPageSpecificPlaceholderConfig = fpCofigDataContext.tblPageSpecificPlaceholderConfigs.Find(tblPageSpecificPlaceholderConfigDto.Id);
                    tblPageSpecificPlaceholderConfigDto.CreatedBy = tblPageSpecificPlaceholderConfig.CreatedBy;
                    tblPageSpecificPlaceholderConfigDto.CreatedOn = tblPageSpecificPlaceholderConfig.CreatedOn;

                    Mapper.Map(tblPageSpecificPlaceholderConfigDto, tblPageSpecificPlaceholderConfig);
                    fpCofigDataContext.SaveChanges();
                    result = tblPageSpecificPlaceholderConfig.Id;
                }//add
                else
                {
                    var tblPageSpecificPlaceholderConfig = new tblPageSpecificPlaceholderConfig();
                    Mapper.Map(tblPageSpecificPlaceholderConfigDto, tblPageSpecificPlaceholderConfig);
                    fpCofigDataContext.tblPageSpecificPlaceholderConfigs.Add(tblPageSpecificPlaceholderConfig);
                    fpCofigDataContext.SaveChanges();
                    result = tblPageSpecificPlaceholderConfig.Id;
                }
                return result;
            }
        }
 /// <summary>
 /// Delete page specfic place holder
 /// </summary>
 /// <param name="pageSpecificPlaceholderId"></param>
 /// <param name="pageSpecificPlaceholder"></param>
 /// <returns></returns>
 public bool DeletePageSpecificPlaceholderConfig(int pageSpecificPlaceholderId, SolutionEnums.PageSpecificPlaceholder pageSpecificPlaceholder)
 {
     int result = 0;
     using (var fpCofigDataContext = new FPConfigEntities())
     {
         var pageSpecificTempletePlaceHolder = fpCofigDataContext.tblPageSpecificPlaceholderConfigs.Find(pageSpecificPlaceholderId);
         switch (pageSpecificPlaceholder)
         {
             case SolutionEnums.PageSpecificPlaceholder.Top:
                 pageSpecificTempletePlaceHolder.TopFrameHTML = string.Empty;
                 break;
             case SolutionEnums.PageSpecificPlaceholder.Left:
                 pageSpecificTempletePlaceHolder.LeftFrameHTML = string.Empty;
                 break;
             case SolutionEnums.PageSpecificPlaceholder.Right:
                 pageSpecificTempletePlaceHolder.RightFrameHTML = string.Empty;
                 break;
             case SolutionEnums.PageSpecificPlaceholder.Bottom:
                 pageSpecificTempletePlaceHolder.BottomFrameHTML = string.Empty;
                 break;
         }
         result = fpCofigDataContext.SaveChanges();
     }
     return true;
 }
 /// <summary>
 /// Get list of process
 /// </summary>
 /// <returns></returns>
 public List<tblProcessDto> GetAllProcess()
 {
     using (var FPConfigEntitiesDataContext = new FPConfigEntities())
     {
         Mapper.CreateMap<tblProcess, tblProcessDto>();
         return Mapper.Map<List<tblProcess>, List<tblProcessDto>>(FPConfigEntitiesDataContext.tblProcesses.ToList());
     }
 }
 /// <summary>
 /// Get list of pending email queue
 /// </summary>
 /// <returns></returns>
 public List<tblEmailQueueDto> GetPendingEmailQueue()
 {
     using (var FPConfigEntitiesDataContext = new FPConfigEntities())
     {
         Mapper.CreateMap<tblEmailQueue, tblEmailQueueDto>();
         return Mapper.Map<List<tblEmailQueue>, List<tblEmailQueueDto>>(FPConfigEntitiesDataContext.tblEmailQueues.ToList());
     }
 }
 /// <summary>
 /// Get Process Email Template By Id
 /// </summary>
 /// <returns></returns>
 public tblProcessEmailTemplateDto GetProcessEmailTemplate(int id)
 {
     using (var FPConfigEntitiesDataContext = new FPConfigEntities())
     {
         Mapper.CreateMap<tblProcessEmailTemplate, tblProcessEmailTemplateDto>();
         Mapper.CreateMap<tblProcess, tblProcessDto>();
         var processEmailTemplate = FPConfigEntitiesDataContext.tblProcessEmailTemplates.Find(id);
         return Mapper.Map(processEmailTemplate, new tblProcessEmailTemplateDto());
     }
 }
        /// <summary>
        /// Returns list of static html page
        /// </summary>
        /// <returns></returns>
        public List<tblPageSpecificPlaceholderConfigDto> GetAllPageSpecificPlaceholderConfig()
        {
            var pageSpecificPlaceholderConfigDto = new List<tblPageSpecificPlaceholderConfigDto>();
            using (var dbFPConfig = new FPConfigEntities())
            {
                Mapper.CreateMap<tblPageSpecificPlaceholderConfig, tblPageSpecificPlaceholderConfigDto>();

                var pageSpecificPlaceholderConfigList = dbFPConfig.tblPageSpecificPlaceholderConfigs;

                if (pageSpecificPlaceholderConfigList != null)
                {
                    Mapper.Map(pageSpecificPlaceholderConfigList, pageSpecificPlaceholderConfigDto);
                }
            }
            return pageSpecificPlaceholderConfigDto;
        }
        /// <summary>
        /// Get list of master configuration
        /// </summary>
        /// <returns></returns>
        public tblMasterConfigurationDto GetMasterConfiguration()
        {
            tblMasterConfigurationDto objMastConfig = new tblMasterConfigurationDto();
            using (var dbMasterConfig = new FPConfigEntities())
            {
                Mapper.CreateMap<tblMasterConfig, tblMasterConfigurationDto>();

                var mstConfig = (from Config in dbMasterConfig.tblMasterConfigs
                                 select Config).FirstOrDefault();

                if (mstConfig != null)
                {
                    Mapper.Map(mstConfig, objMastConfig);
                }
            }
            return objMastConfig;
        }
 /// <summary>
 /// Updates email queue
 /// </summary>
 /// <param name="masterConfigDto"></param>
 /// <returns>int</returns>
 public int UpdateEmailQueue(tblEmailQueueDto emailQueueDto)
 {
     Mapper.CreateMap<tblEmailQueueDto, tblEmailQueue>();
     int result = 0;
     try
     {
         using (var fpCofigDataContext = new FPConfigEntities())
         {
             var emailQueue = fpCofigDataContext.tblEmailQueues.Find(emailQueueDto.Id);
             Mapper.Map(emailQueueDto, emailQueue);
             result = fpCofigDataContext.SaveChanges();
         }
     }
     catch
     {
         return -1;
     }
     return result;
 }
 /// <summary>
 /// Delete  ProcessEmailTemplate
 /// </summary>
 /// <param name="masterConfigDto"></param>
 /// <returns>int</returns>
 public bool DeleteProcessEmailTemplate(int processEmailTemplateId)
 {
     try
     {
         using (var FPConfigEntities = new FPConfigEntities())
         {
             var processEmailTemplate = FPConfigEntities.tblProcessEmailTemplates.Find(processEmailTemplateId);
             if (processEmailTemplateId > 0)
             {
                 FPConfigEntities.tblProcessEmailTemplates.Remove(processEmailTemplate);
                 FPConfigEntities.SaveChanges();
             }
         }
     }
     catch
     {
         return false;
     }
     return true;
 }
        /// <summary>
        /// Saves/Updates ProcessEmailTemplate
        /// </summary>
        /// <param name="masterConfigDto"></param>
        /// <returns>int</returns>
        public int SaveProcessEmailTemplate(tblProcessEmailTemplateDto processEmailTemplateDto)
        {
            Mapper.CreateMap<tblProcessEmailTemplateDto, tblProcessEmailTemplate>()
                .ForMember(dest => dest.tblProcess, opt => opt.Ignore());

            int result = 0;
            try
            {
                using (var FPConfigEntities = new FPConfigEntities())
                {
                    var processEmailTemplate = new tblProcessEmailTemplate();
                    //Update mode
                    if (processEmailTemplateDto.Id > 0)
                    {
                        processEmailTemplate = FPConfigEntities.tblProcessEmailTemplates.Find(processEmailTemplateDto.Id);
                        Mapper.Map(processEmailTemplateDto, processEmailTemplate);
                        result = FPConfigEntities.SaveChanges();
                    }
                    //New configuration
                    else
                    {
                        Mapper.Map(processEmailTemplateDto, processEmailTemplate);
                        FPConfigEntities.tblProcessEmailTemplates.Add(processEmailTemplate);
                        result = FPConfigEntities.SaveChanges();
                    }
                }
            }
            catch
            {
                return -1;
            }
            return result;
        }