public async Task <ResponseAC> UpdateAssignedTelephone(long userId, AssignTelephoneDetailAC assignTelephoneDetailAC, string loginUserName) { ResponseAC responseAC = new ResponseAC(); Telephonenumberallocation telephoneNumberAllocation = await _dbTeleBilling_V01Context.Telephonenumberallocation.FirstAsync(x => x.Id == assignTelephoneDetailAC.Id); #region Transaction Log Entry if (telephoneNumberAllocation.TransactionId == null) { telephoneNumberAllocation.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID(); } var jsonSerailzeObj = JsonConvert.SerializeObject(telephoneNumberAllocation); await _iLogManagement.SaveRequestTraseLog(Convert.ToInt64(telephoneNumberAllocation.TransactionId), userId, Convert.ToInt64(EnumList.TransactionTraseLog.UpdateRecord), jsonSerailzeObj); #endregion telephoneNumberAllocation = _mapper.Map(assignTelephoneDetailAC, telephoneNumberAllocation); telephoneNumberAllocation.UpdatedBy = userId; telephoneNumberAllocation.UpdatedDate = DateTime.Now; _dbTeleBilling_V01Context.Update(telephoneNumberAllocation); await _dbTeleBilling_V01Context.SaveChangesAsync(); List <Telephonenumberallocationpackage> telePhoneNumberAllocationPackages = await _dbTeleBilling_V01Context.Telephonenumberallocationpackage.Where(x => x.TelephoneNumberAllocationId == telephoneNumberAllocation.Id && !x.IsDelete).ToListAsync(); foreach (var item in telePhoneNumberAllocationPackages) { item.IsDelete = true; item.UpdatedBy = userId; item.UpdatedDate = DateTime.Now; } _dbTeleBilling_V01Context.UpdateRange(telePhoneNumberAllocationPackages); _dbTeleBilling_V01Context.SaveChanges(); #region Update Packages telePhoneNumberAllocationPackages = new List <Telephonenumberallocationpackage>(); foreach (var item in assignTelephoneDetailAC.TelePhonePackageDetails) { Telephonenumberallocationpackage telePhoneNumberAllocationPackage = new Telephonenumberallocationpackage(); telePhoneNumberAllocationPackage.PackageId = item.PackageId; telePhoneNumberAllocationPackage.ServiceId = item.ServiceId; telePhoneNumberAllocationPackage.StartDate = item.StartDate.AddDays(1); telePhoneNumberAllocationPackage.EndDate = item.EndDate.AddDays(1); telePhoneNumberAllocationPackage.TelephoneNumberAllocationId = telephoneNumberAllocation.Id; telePhoneNumberAllocationPackages.Add(telePhoneNumberAllocationPackage); } await _dbTeleBilling_V01Context.AddRangeAsync(telePhoneNumberAllocationPackages); await _dbTeleBilling_V01Context.SaveChangesAsync(); #endregion await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.EditAssignTelephone, loginUserName, userId, "Assign Telephone(" + telephoneNumberAllocation.TelephoneNumber + ")", (int)EnumList.ActionTemplateTypes.Edit, telephoneNumberAllocation.Id); responseAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success); responseAC.Message = _iStringConstant.AssignedTelePhoneEditSuccessfully; return(responseAC); }
public async Task <ResponseAC> AddAssignedTelephone(long userId, AssignTelephoneDetailAC assignTelephoneDetailAC, string loginUserName) { ResponseAC responseAC = new ResponseAC(); try { Telephonenumberallocation telephoneNumberAllocation = _mapper.Map <Telephonenumberallocation>(assignTelephoneDetailAC); telephoneNumberAllocation.CreatedBy = userId; telephoneNumberAllocation.CreatedDate = DateTime.Now; telephoneNumberAllocation.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID(); telephoneNumberAllocation.IsActive = true; await _dbTeleBilling_V01Context.AddAsync(telephoneNumberAllocation); await _dbTeleBilling_V01Context.SaveChangesAsync(); List <Telephonenumberallocationpackage> telePhoneNumberAllocationPackages = new List <Telephonenumberallocationpackage>(); foreach (var item in assignTelephoneDetailAC.TelePhonePackageDetails) { Telephonenumberallocationpackage telePhoneNumberAllocationPackage = new Telephonenumberallocationpackage(); telePhoneNumberAllocationPackage.PackageId = item.PackageId; telePhoneNumberAllocationPackage.ServiceId = item.ServiceId; telePhoneNumberAllocationPackage.StartDate = item.StartDate.AddDays(1); telePhoneNumberAllocationPackage.EndDate = item.EndDate.AddDays(1); telePhoneNumberAllocationPackage.TelephoneNumberAllocationId = telephoneNumberAllocation.Id; telePhoneNumberAllocationPackages.Add(telePhoneNumberAllocationPackage); } await _dbTeleBilling_V01Context.AddRangeAsync(telePhoneNumberAllocationPackages); await _dbTeleBilling_V01Context.SaveChangesAsync(); await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.AssignTelephone, loginUserName, userId, "Assign Telephone(" + telephoneNumberAllocation.TelephoneNumber + ")", (int)EnumList.ActionTemplateTypes.Assign, telephoneNumberAllocation.Id); responseAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success); responseAC.Message = _iStringConstant.TelephoneAssignedSuccessfully; } catch (Exception ex) { throw ex; } return(responseAC); }
public async Task <BulkAssignTelephoneResponseAC> UploadBulkAssignTelePhone(long userId, ExcelUploadResponseAC exceluploadDetail, string loginUserName) { BulkAssignTelephoneResponseAC bulkAssignTelephoneResponseAC = new BulkAssignTelephoneResponseAC(); List <ExcelUploadResult> excelUploadResultList = new List <ExcelUploadResult>(); FileInfo fileinfo = new FileInfo(Path.Combine(exceluploadDetail.FilePath, exceluploadDetail.FileNameGuid)); try { using (ExcelPackage package = new ExcelPackage(fileinfo)) { for (int i = 1; i <= package.Workbook.Worksheets.Count(); i++) { ExcelWorksheet workSheet = package.Workbook.Worksheets[i]; string sheetName = package.Workbook.Worksheets[i].Name; int totalRows = workSheet.Dimension.Rows; int totalColums = workSheet.Dimension.Columns; for (int j = 1; j <= totalRows - 1; j++) { string mobileNumber = workSheet.Cells[j + 1, 1].Value != null ? workSheet.Cells[j + 1, 1].Value.ToString() : string.Empty; string assignType = workSheet.Cells[j + 1, 2].Value != null ? workSheet.Cells[j + 1, 2].Value.ToString() : string.Empty; string pfNumber = workSheet.Cells[j + 1, 3].Value != null ? workSheet.Cells[j + 1, 3].Value.ToString() : string.Empty; string packageName = workSheet.Cells[j + 1, 4].Value != null ? workSheet.Cells[j + 1, 4].Value.ToString() : string.Empty; string startDate = workSheet.Cells[j + 1, 5].Value != null ? workSheet.Cells[j + 1, 5].Value.ToString() : string.Empty; string endDate = workSheet.Cells[j + 1, 6].Value != null ? workSheet.Cells[j + 1, 6].Value.ToString() : string.Empty; if (!string.IsNullOrEmpty(mobileNumber) && !string.IsNullOrEmpty(assignType) && !string.IsNullOrEmpty(pfNumber) && !string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(packageName) && !string.IsNullOrEmpty(endDate)) { Telephonenumberallocation telephoneNumberAllocation = new Telephonenumberallocation(); Telephonenumberallocationpackage telePhoneNumberAllocationPackage = new Telephonenumberallocationpackage(); bulkAssignTelephoneResponseAC.TotalRecords += 1; Telephonenumber telephoneNumber = await _dbTeleBilling_V01Context.Telephonenumber.FirstOrDefaultAsync(x => x.TelephoneNumber1.ToLower().Trim() == mobileNumber.ToLower().Trim() && x.IsActive && !x.IsDelete); if (telephoneNumber != null) { FixAssigntype fixAssigntype = await _dbTeleBilling_V01Context.FixAssigntype.FirstOrDefaultAsync(x => x.IsActive && x.Name == assignType); if (fixAssigntype != null) { MstEmployee mstEmployee = await _dbTeleBilling_V01Context.MstEmployee.FirstOrDefaultAsync(x => x.IsActive && !x.IsDelete && x.EmpPfnumber.ToLower().Trim() == pfNumber.ToLower().Trim()); if (mstEmployee != null) { Providerpackage providerPackage = await _dbTeleBilling_V01Context.Providerpackage.FirstOrDefaultAsync(x => x.IsActive && !x.IsDelete && x.Name.ToLower().Trim() == packageName.ToLower().Trim()); if (providerPackage != null) { if (!string.IsNullOrEmpty(startDate)) { if (!string.IsNullOrEmpty(endDate)) { DateTime newStartDate; DateTime newEndDate; if (DateTime.TryParse(startDate, out newStartDate)) { String.Format("{0:d/MM/yyyy}", newStartDate); if (DateTime.TryParse(endDate, out newEndDate)) { String.Format("{0:d/MM/yyyy}", newEndDate); string lineStatus = workSheet.Cells[j + 1, 7].Value != null ? workSheet.Cells[j + 1, 7].Value.ToString() : ""; FixLinestatus fixLineStatus = await _dbTeleBilling_V01Context.FixLinestatus.FirstOrDefaultAsync(x => x.IsActive && x.Name.ToLower().Trim() == lineStatus.ToLower().Trim()); if (fixLineStatus != null) { if (telephoneNumber.ProviderId == providerPackage.ProviderId) { Telephonenumberallocation newTelephoneNumberAllocation = _dbTeleBilling_V01Context.Telephonenumberallocation.FirstOrDefault(x => x.TelephoneNumberId == telephoneNumber.Id && !x.IsDelete); if (newTelephoneNumberAllocation != null) { Telephonenumberallocationpackage newTelePhoneNumberAllocationPackage = await _dbTeleBilling_V01Context.Telephonenumberallocationpackage.FirstOrDefaultAsync(x => x.TelephoneNumberAllocationId == newTelephoneNumberAllocation.Id && x.PackageId == providerPackage.Id && !x.IsDelete); if (newTelePhoneNumberAllocationPackage == null) { newTelePhoneNumberAllocationPackage = new Telephonenumberallocationpackage(); newTelePhoneNumberAllocationPackage.ServiceId = providerPackage.ServiceTypeId; newTelePhoneNumberAllocationPackage.StartDate = newStartDate; newTelePhoneNumberAllocationPackage.EndDate = newEndDate; newTelePhoneNumberAllocationPackage.PackageId = providerPackage.Id; bulkAssignTelephoneResponseAC.SuccessRecords += 1; newTelePhoneNumberAllocationPackage.TelephoneNumberAllocationId = newTelephoneNumberAllocation.Id; await _dbTeleBilling_V01Context.AddAsync(newTelePhoneNumberAllocationPackage); await _dbTeleBilling_V01Context.SaveChangesAsync(); await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.AssignBulkTelephone, loginUserName, userId, "Telephone Assign(" + newTelephoneNumberAllocation.TelephoneNumber + ")", (int)EnumList.ActionTemplateTypes.Upload, newTelephoneNumberAllocation.Id); } else { //TelphoneNumbeAlready Assigned bulkAssignTelephoneResponseAC.SkipRecords += 1; string message = _iStringConstant.TelphoneNumberPackageAlreadyAssigned.Replace("{{$telephonenumber$}}", mobileNumber); excelUploadResultList = AddedFileDataResponse(1, j + 1, packageName, message, sheetName, excelUploadResultList); } } else { telephoneNumberAllocation.EmployeeId = mstEmployee.UserId; telephoneNumberAllocation.EmpPfnumber = mstEmployee.EmpPfnumber; telephoneNumberAllocation.TelephoneNumberId = telephoneNumber.Id; telephoneNumberAllocation.TelephoneNumber = telephoneNumber.TelephoneNumber1; telephoneNumberAllocation.LineStatusId = fixLineStatus.Id; telephoneNumberAllocation.IsActive = true; telephoneNumberAllocation.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID(); telephoneNumberAllocation.CreatedBy = userId; telephoneNumberAllocation.CreatedDate = DateTime.Now; telephoneNumberAllocation.AssignTypeId = fixAssigntype.Id; bulkAssignTelephoneResponseAC.SuccessRecords += 1; await _dbTeleBilling_V01Context.AddAsync(telephoneNumberAllocation); await _dbTeleBilling_V01Context.SaveChangesAsync(); telePhoneNumberAllocationPackage.ServiceId = providerPackage.ServiceTypeId; telePhoneNumberAllocationPackage.StartDate = newStartDate; telePhoneNumberAllocationPackage.EndDate = newEndDate; telePhoneNumberAllocationPackage.PackageId = providerPackage.Id; telePhoneNumberAllocationPackage.TelephoneNumberAllocationId = telephoneNumberAllocation.Id; await _dbTeleBilling_V01Context.AddAsync(telePhoneNumberAllocationPackage); await _dbTeleBilling_V01Context.SaveChangesAsync(); await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.AssignBulkTelephone, loginUserName, userId, "Telephone Assign(" + newTelephoneNumberAllocation.TelephoneNumber + ")", (int)EnumList.ActionTemplateTypes.Upload, newTelephoneNumberAllocation.Id); } } else { //Packge not same bulkAssignTelephoneResponseAC.SkipRecords += 1; excelUploadResultList = AddedFileDataResponse(4, j + 1, "Given package not valid for mobilenumber(" + mobileNumber + ")", _iStringConstant.PackageNotMatchWithTelephoneNumber, sheetName, excelUploadResultList); } } else { //LineStatus Not Exists bulkAssignTelephoneResponseAC.SkipRecords += 1; excelUploadResultList = AddedFileDataResponse(7, j + 1, lineStatus, _iStringConstant.LineStatusNotExists, sheetName, excelUploadResultList); } } else { //End Date Not Valid bulkAssignTelephoneResponseAC.SkipRecords += 1; excelUploadResultList = AddedFileDataResponse(6, j + 1, endDate, _iStringConstant.EndDateNotValid, sheetName, excelUploadResultList); } } else { //Start Date Not Valid bulkAssignTelephoneResponseAC.SkipRecords += 1; excelUploadResultList = AddedFileDataResponse(5, j + 1, startDate, _iStringConstant.StartDateNotValid, sheetName, excelUploadResultList); } } else { //End Date Is Empty bulkAssignTelephoneResponseAC.SkipRecords += 1; excelUploadResultList = AddedFileDataResponse(6, j + 1, endDate, _iStringConstant.EndDateIsEmpty, sheetName, excelUploadResultList); } } else { //Start Date Is Empty bulkAssignTelephoneResponseAC.SkipRecords += 1; excelUploadResultList = AddedFileDataResponse(5, j, startDate, _iStringConstant.StartDateIsEmpty, sheetName, excelUploadResultList); } } else { //Package Not Exists bulkAssignTelephoneResponseAC.SkipRecords += 1; excelUploadResultList = AddedFileDataResponse(4, j + 1, packageName, _iStringConstant.PackageNotExists, sheetName, excelUploadResultList); } } else { //Employee Not Exists bulkAssignTelephoneResponseAC.SkipRecords += 1; excelUploadResultList = AddedFileDataResponse(3, j, pfNumber, _iStringConstant.EmployeeNotExists, sheetName, excelUploadResultList); } //else //{ //TelphoneNumbeAlready Assigned //bulkAssignTelephoneResponseAC.SkipRecords += 1; //excelUploadResultList = AddedFileDataResponse(1, j + 1, mobileNumber, _iStringConstant.TelphoneNumberAlreadyAssigned, sheetName, excelUploadResultList); //} } else { //Employee Not Exists bulkAssignTelephoneResponseAC.SkipRecords += 1; excelUploadResultList = AddedFileDataResponse(2, j, assignType, _iStringConstant.AssignTypeNotExists, sheetName, excelUploadResultList); } } else { //PhoneNumber Not Exists bulkAssignTelephoneResponseAC.SkipRecords += 1; excelUploadResultList = AddedFileDataResponse(1, j + 1, mobileNumber, _iStringConstant.PhoneNumberNotExists, sheetName, excelUploadResultList); } } } } } if (File.Exists(Path.Combine(exceluploadDetail.FilePath, exceluploadDetail.FileNameGuid))) { File.Delete(Path.Combine(exceluploadDetail.FilePath, exceluploadDetail.FileNameGuid)); } bulkAssignTelephoneResponseAC.excelUploadResultList = excelUploadResultList; return(bulkAssignTelephoneResponseAC); } catch (Exception ex) { if (File.Exists(Path.Combine(exceluploadDetail.FilePath, exceluploadDetail.FileNameGuid))) { File.Delete(Path.Combine(exceluploadDetail.FilePath, exceluploadDetail.FileNameGuid)); } throw ex; } }