public async Task <ResponseAC> EditExcelMapping(ExcelMappingAC excelMappingAC, long userId, string loginUserName) { ResponseAC responeAC = new ResponseAC(); try { if (excelMappingAC.dbfieldList.Count() == 0) { responeAC.Message = "Mapping Column Is Missing"; responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Error); return(responeAC); } Mappingexcel mappingexcel = new Mappingexcel(); mappingexcel = await _dbTeleBilling_V01Context.Mappingexcel.FirstOrDefaultAsync(x => x.ProviderId == excelMappingAC.ProviderId && x.ServiceTypeId == excelMappingAC.ServiceTypeId && !x.IsDelete && x.Id == excelMappingAC.Id); if (mappingexcel != null && mappingexcel.Id > 0) { #region Check For Common Mapped service not already exists bool IsValidServices = true; if (excelMappingAC.ServiceTypeIdInline != null) { if (excelMappingAC.ServiceTypeIdInline.Count() > 0) { List <DrpResponseAC> ValidServiceTypeIdInline = _iStaticRepository.ProviderCommonServiceTypeList(mappingexcel.ProviderId, mappingexcel.Id); if (ValidServiceTypeIdInline != null) { if (ValidServiceTypeIdInline.Count() > 0) { var invalidService = excelMappingAC.ServiceTypeIdInline.Where(x => !ValidServiceTypeIdInline.Select(s => s.Id).Contains(x.Id)).ToList(); if (invalidService != null) { if (invalidService.Count() > 0) { IsValidServices = false; } } } else { IsValidServices = false; } } else { IsValidServices = false; } if (!IsValidServices) { responeAC.Message = "selected services for provider mapping is invalid."; responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Error); return(responeAC); } } } #endregion #region Transaction Log Entry if (mappingexcel.TransactionId == null) { mappingexcel.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID(); } var jsonSerailzeObj = JsonConvert.SerializeObject(mappingexcel); await _iLogManagement.SaveRequestTraseLog(Convert.ToInt64(mappingexcel.TransactionId), userId, Convert.ToInt64(EnumList.TransactionTraseLog.UpdateRecord), jsonSerailzeObj); #endregion mappingexcel.HaveHeader = excelMappingAC.HaveHeader; mappingexcel.HaveTitle = excelMappingAC.HaveTitle; mappingexcel.TitleName = excelMappingAC.TitleName; mappingexcel.WorkSheetNo = Convert.ToInt64(excelMappingAC.WorkSheetNo); mappingexcel.ExcelColumnNameForTitle = string.IsNullOrEmpty(excelMappingAC.ExcelColumnNameForTitle) ? "" : excelMappingAC.ExcelColumnNameForTitle; mappingexcel.ExcelReadingColumn = string.IsNullOrEmpty(excelMappingAC.ExcelReadingColumn) ? "0" : excelMappingAC.ExcelReadingColumn; mappingexcel.UpdatedBy = userId; mappingexcel.UpdatedDate = DateTime.Now; _dbTeleBilling_V01Context.Update(mappingexcel); await _dbTeleBilling_V01Context.SaveChangesAsync(); responeAC.Message = _iStringConstant.ExcelMappingUpdatedSuccessfully; responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success); await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.EditExcelMapping, loginUserName, userId, "Excel mapping", (int)EnumList.ActionTemplateTypes.Edit, mappingexcel.Id); if (mappingexcel.Id > 0) { #region --> Remove Old Common Mapping List <Mappingexcel> mappingCommonList = new List <Mappingexcel>(); mappingCommonList = await _dbTeleBilling_V01Context.Mappingexcel.Where(x => x.MappedMappingId == mappingexcel.Id).ToListAsync(); if (mappingCommonList != null) { if (mappingCommonList.Count() > 0) { _dbTeleBilling_V01Context.RemoveRange(mappingCommonList); await _dbTeleBilling_V01Context.SaveChangesAsync(); } } #endregion if (excelMappingAC.ServiceTypeIdInline != null) { if (excelMappingAC.ServiceTypeIdInline.Count() > 0) { #region ---> Add Common Servive if exists foreach (var serviceType in excelMappingAC.ServiceTypeIdInline) { Mappingexcel mappingexcelCommon = new Mappingexcel(); mappingexcelCommon.Id = 0; mappingexcelCommon.IsActive = true; mappingexcelCommon.ProviderId = excelMappingAC.ProviderId; mappingexcelCommon.CurrencyId = mappingexcel.CurrencyId; mappingexcelCommon.ServiceTypeId = serviceType.Id; mappingexcelCommon.HaveHeader = excelMappingAC.HaveHeader; mappingexcelCommon.HaveTitle = excelMappingAC.HaveTitle; mappingexcelCommon.TitleName = excelMappingAC.TitleName; mappingexcelCommon.WorkSheetNo = Convert.ToInt64(excelMappingAC.WorkSheetNo); mappingexcelCommon.ExcelColumnNameForTitle = string.IsNullOrEmpty(excelMappingAC.ExcelColumnNameForTitle) ? "" : excelMappingAC.ExcelColumnNameForTitle; mappingexcelCommon.ExcelReadingColumn = string.IsNullOrEmpty(excelMappingAC.ExcelReadingColumn) ? "0" : excelMappingAC.ExcelReadingColumn; mappingexcelCommon.CreatedBy = userId; mappingexcelCommon.CreatedDate = DateTime.Now; mappingexcelCommon.TransactionId = mappingexcel.TransactionId; mappingexcelCommon.IsCommonMapped = true; mappingexcelCommon.MappedMappingId = mappingexcel.Id; mappingexcelCommon.MappedServiceTypeId = mappingexcel.ServiceTypeId; await _dbTeleBilling_V01Context.AddAsync(mappingexcelCommon); await _dbTeleBilling_V01Context.SaveChangesAsync(); } #endregion } } #region --> Update Mapping column Details if (excelMappingAC.dbfieldList.Count() > 0) { #region --> remove old Mapping List <Mappingexcelcolumn> excelcolumnlst = new List <Mappingexcelcolumn>(); excelcolumnlst = await _dbTeleBilling_V01Context.Mappingexcelcolumn.Where(x => x.MappingExcelId == mappingexcel.Id).ToListAsync(); if (excelcolumnlst != null) { _dbTeleBilling_V01Context.RemoveRange(excelcolumnlst); await _dbTeleBilling_V01Context.SaveChangesAsync(); } #endregion List <Mappingexcelcolumn> mappingExcelColumnslst = new List <Mappingexcelcolumn>(); foreach (var item in excelMappingAC.dbfieldList) { if (!string.IsNullOrEmpty(item.ColumnAddress)) { Mappingexcelcolumn excelColumn = new Mappingexcelcolumn(); excelColumn.MappingExcelId = mappingexcel.Id; excelColumn.MappingServiceTypeFieldId = item.Id; excelColumn.ExcelcolumnName = item.ColumnAddress; excelColumn.FormatField = item.FormatField; mappingExcelColumnslst.Add(excelColumn); } } await _dbTeleBilling_V01Context.AddRangeAsync(mappingExcelColumnslst); await _dbTeleBilling_V01Context.SaveChangesAsync(); responeAC.Message = _iStringConstant.ExcelMappingUpdatedSuccessfully; responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success); } #endregion } } else { responeAC.Message = _iStringConstant.DataFound; responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Error); } return(responeAC); } catch (Exception e) { responeAC.Message = e.Message.ToString(); responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Error); return(responeAC); } }
public async Task <ResponseAC> AddExcelMapping(ExcelMappingAC excelMappingAC, long userId, string loginUserName) { ResponseAC responeAC = new ResponseAC(); try { if (excelMappingAC.dbfieldList.Count() == 0) { responeAC.Message = "Mapping Column Is Missing"; responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Error); return(responeAC); } if (excelMappingAC != null) { bool IsExistsServices = false; IsExistsServices = await checkExcelMappingExistsForServices(excelMappingAC); if (IsExistsServices) { responeAC.Message = "excel mapping is already exists"; responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Error); return(responeAC); } } if ((await _dbTeleBilling_V01Context.Mappingexcel.FirstOrDefaultAsync(x => x.ProviderId == excelMappingAC.ProviderId && x.ServiceTypeId == excelMappingAC.ServiceTypeId && !x.IsDelete)) == null) { var providerData = await _dbTeleBilling_V01Context.Provider.FirstOrDefaultAsync(x => x.Id == excelMappingAC.ProviderId); Mappingexcel mappingexcel = new Mappingexcel(); mappingexcel.Id = 0; mappingexcel.IsActive = true; mappingexcel.ProviderId = excelMappingAC.ProviderId; mappingexcel.CurrencyId = providerData.CurrencyId; mappingexcel.ServiceTypeId = excelMappingAC.ServiceTypeId; mappingexcel.HaveHeader = excelMappingAC.HaveHeader; mappingexcel.HaveTitle = excelMappingAC.HaveTitle; mappingexcel.TitleName = excelMappingAC.TitleName; mappingexcel.WorkSheetNo = Convert.ToInt64(excelMappingAC.WorkSheetNo); mappingexcel.ExcelColumnNameForTitle = string.IsNullOrEmpty(excelMappingAC.ExcelColumnNameForTitle) ? "" : excelMappingAC.ExcelColumnNameForTitle; mappingexcel.ExcelReadingColumn = string.IsNullOrEmpty(excelMappingAC.ExcelReadingColumn) ? "0" : excelMappingAC.ExcelReadingColumn; mappingexcel.CreatedBy = userId; mappingexcel.CreatedDate = DateTime.Now; mappingexcel.IsCommonMapped = false; mappingexcel.MappedMappingId = 0; mappingexcel.MappedServiceTypeId = 0; mappingexcel.IsDelete = false; mappingexcel.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID(); await _dbTeleBilling_V01Context.AddAsync(mappingexcel); await _dbTeleBilling_V01Context.SaveChangesAsync(); responeAC.Message = _iStringConstant.ExcelMappingAddedSuccessfully; responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success); await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.AddExcelMapping, loginUserName, userId, "Excel mapping", (int)EnumList.ActionTemplateTypes.Add, mappingexcel.Id); if (mappingexcel.Id > 0) { #region ---> Add Common Servive if exists foreach (var serviceType in excelMappingAC.ServiceTypeIdInline) { Mappingexcel mappingexcelCommon = new Mappingexcel(); mappingexcelCommon.Id = 0; mappingexcelCommon.IsActive = true; mappingexcelCommon.ProviderId = excelMappingAC.ProviderId; mappingexcelCommon.CurrencyId = providerData.CurrencyId; mappingexcelCommon.ServiceTypeId = serviceType.Id; mappingexcelCommon.HaveHeader = excelMappingAC.HaveHeader; mappingexcelCommon.HaveTitle = excelMappingAC.HaveTitle; mappingexcelCommon.TitleName = excelMappingAC.TitleName; mappingexcelCommon.WorkSheetNo = Convert.ToInt64(excelMappingAC.WorkSheetNo); mappingexcelCommon.ExcelColumnNameForTitle = excelMappingAC.ExcelColumnNameForTitle; mappingexcelCommon.ExcelReadingColumn = string.IsNullOrEmpty(excelMappingAC.ExcelReadingColumn) ? "" : excelMappingAC.ExcelReadingColumn; mappingexcelCommon.CreatedBy = userId; mappingexcelCommon.CreatedDate = DateTime.Now; mappingexcelCommon.TransactionId = mappingexcel.TransactionId; mappingexcelCommon.IsCommonMapped = true; mappingexcelCommon.MappedMappingId = mappingexcel.Id; mappingexcelCommon.MappedServiceTypeId = mappingexcel.ServiceTypeId; await _dbTeleBilling_V01Context.AddAsync(mappingexcelCommon); await _dbTeleBilling_V01Context.SaveChangesAsync(); } #endregion #region --> ADD Mapping column Details if (excelMappingAC.dbfieldList.Count() > 0) { List <Mappingexcelcolumn> mappingExcelColumnslst = new List <Mappingexcelcolumn>(); foreach (var item in excelMappingAC.dbfieldList) { if (!string.IsNullOrEmpty(item.ColumnAddress)) { Mappingexcelcolumn excelColumn = new Mappingexcelcolumn(); excelColumn.MappingExcelId = mappingexcel.Id; excelColumn.MappingServiceTypeFieldId = item.Id; excelColumn.ExcelcolumnName = item.ColumnAddress; excelColumn.FormatField = item.FormatField; mappingExcelColumnslst.Add(excelColumn); } } await _dbTeleBilling_V01Context.AddRangeAsync(mappingExcelColumnslst); await _dbTeleBilling_V01Context.SaveChangesAsync(); responeAC.Message = _iStringConstant.ExcelMappingAddedSuccessfully; responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success); } #endregion } } else { responeAC.Message = _iStringConstant.ExcelMappingExists; responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Error); } return(responeAC); } catch (Exception e) { responeAC.Message = e.Message.ToString(); responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Error); return(responeAC); } }