public List<KeyOperationResult> SaveGeneratedReturnReport(ReturnReport returnReport) { List<KeyOperationResult> results = VerificationReturnReport(returnReport); keyRepository.UpdateKeys(results.Where(k => !k.Failed).Select(k => k.Key).ToList(), true, null); SaveReturnReport(returnReport); return results; }
public void UpdateReturnReport(ReturnReport returnKey) { using (var context = GetContext()) { UpdateReturnKeyAck(context, returnKey); context.SaveChanges(); } }
public void InsertReturnReportAndKeys(ReturnReport returnKey) { using (var context = GetContext()) { context.Configuration.AutoDetectChangesEnabled = false; context.ReturnReports.Add(returnKey); foreach (var key in returnKey.ReturnReportKeys) { context.ReturnReportKeys.Add(key); } context.SaveChanges(); } }
public void UpdateReturnKeyAck(ReturnReport returnKey, KeyStoreContext context) { UsingContext(ref context, () => { context.Configuration.AutoDetectChangesEnabled = false; UpdateReturnKeyAck(context, returnKey); foreach (ReturnReportKey key in returnKey.ReturnReportKeys) { context.ReturnReportKeys.Attach(key); context.Entry(key).State = EntityState.Modified; } }); }
public static ReturnReport ToReturnReport(this IEnumerable<ReturnKeyModel> returnKeys, string OemRmaNumber,DateTime OemRmaDate, bool ReturnNoCredit) { int i = 0; ReturnReport request = new ReturnReport() { CustomerReturnUniqueId = System.Guid.NewGuid(), OemRmaNumber = OemRmaNumber, OemRmaDate = OemRmaDate, OemRmaDateUTC = OemRmaDate.ToUniversalTime(), SoldToCustomerId = returnKeys.First().ReturnReportKey.keyInfo.SoldToCustomerId, ReturnNoCredit = ReturnNoCredit, ReturnReportStatusId = (int)ReturnReportStatus.Reported, ReturnReportKeys = returnKeys.Where(k => k.ReturnReportKey.IsSelected).Select(k => new ReturnReportKey() { OemRmaLineNumber = i + 1, ReturnTypeId = ToReturKeyType(k.SelectReturnRequestType), KeyId = k.ReturnReportKey.keyInfo.KeyId, PreProductKeyStateId = k.ReturnReportKey.keyInfo.KeyStateId, }).ToList() }; return request; }
//Export Return Keys to MS public List<KeyOperationResult> ExportReturnKeys(ReturnReport request, ExportParameters exportParameters) { if (request == null || request.ReturnReportKeys.Count() <= 0) throw new ArgumentException("export keys is null!"); var keys = request.ReturnReportKeys.Select(k => new KeyInfo() { KeyId = k.KeyId }).ToList(); var result = ValidateKeys(keys, ValidExportReturnKey); if (result.All(r => !r.Failed)) { string fileContent = GenerateReturnKeysToFile(request, exportParameters); List<KeyInfo> keysToUpdate = result.Select(r => r.KeyInDb).ToList(); returnKeyRepository.InsertReturnReportAndKeys(request); keyRepository.UpdateKeys(keysToUpdate, false, null); RecordExportLog(keysToUpdate, exportParameters, fileContent, exportParameters.OutputPath); } result.ForEach(r => { r.Key = r.KeyInDb; }); return result; }
private void UpdateReturnByAck(ReturnReport returnReport, ReturnReport dbReturnReport, KeyStoreContext context = null) { if (dbReturnReport == null) throw new DisException("Failed to get data from database to match the contents of this file!"); if (dbReturnReport.ReturnReportStatus == ReturnReportStatus.Completed) throw new DisException("Return.ack has got and completed!"); dbReturnReport.ReturnUniqueId =(returnReport.ReturnUniqueId==System.Guid.Empty?null: returnReport.ReturnUniqueId); dbReturnReport.MsReturnNumber = returnReport.MsReturnNumber; dbReturnReport.ReturnDateUTC = returnReport.ReturnDateUTC; dbReturnReport.OemRmaDateUTC = returnReport.OemRmaDateUTC; dbReturnReport.SoldToCustomerName = returnReport.SoldToCustomerName; dbReturnReport.ReturnReportStatus = ReturnReportStatus.Completed; if (dbReturnReport.ReturnReportKeys != null && dbReturnReport.ReturnReportKeys.Count > 0) { Func<ReturnReportKey, ReturnReportKey, ReturnReportKey> updateReturnReportAck = (k1, k2) => { k1.MsReturnLineNumber = k2.MsReturnLineNumber; k1.OemRmaLineNumber = k2.OemRmaLineNumber; k1.LicensablePartNumber = k2.LicensablePartNumber; k1.ReturnReasonCode = k2.ReturnReasonCode; k1.ReturnReasonCodeDescription = k2.ReturnReasonCodeDescription; return k1; }; var update = (from db in dbReturnReport.ReturnReportKeys join ack in returnReport.ReturnReportKeys on db.KeyId equals ack.KeyId select updateReturnReportAck(db, ack)).ToList(); } returnKeyRepository.UpdateReturnKeyAck(dbReturnReport, context); }
private void SaveReturnReport(ReturnReport returnReport) { returnReport.OemRmaDate = DateTime.Now; returnReport.ReturnReportStatus = ReturnReportStatus.Generated; returnReport.CustomerReturnUniqueId = Guid.NewGuid(); returnKeyRepository.InsertReturnReportAndKeys(returnReport); }
private string GenerateReturnKeysToFile(ReturnReport report, ExportParameters exportParameters) { ReturnRequest request = new ReturnRequest() { OEMRMANumber = report.OemRmaNumber, OEMRMADate = report.OemRmaDate, SoldToCustomerID = report.SoldToCustomerId, ReturnNoCredit = report.ReturnNoCredit, ReturnLineItems = report.ReturnReportKeys.Select(k => new ReturnLineItem() { OEMRMALineNumber = k.OemRmaLineNumber, ProductKeyID = k.KeyId, ReturnTypeID = k.ReturnTypeId }).ToArray() }; KeyManagerHelper.CreateFilePath(exportParameters.OutputPath); Serializer.WriteToXml(request, exportParameters.OutputPath); return KeyManagerHelper.GetXmlResult(request); }
public void UpdateReturnWhenAckFailed(ReturnReport returnReport) { returnReport.ReturnReportStatus = ReturnReportStatus.Failed; returnKeyRepository.UpdateReturnReport(returnReport); }
public void UpdateReturnReportToCarbonCopyCompleted(ReturnReport returnReport) { returnReport.ReturnReportStatus = ReturnReportStatus.CarbonCopyCompleted; returnKeyRepository.UpdateReturnReport(returnReport); }
public void UpdateReturnAfterReported(ReturnReport returnReport) { if (returnReport.CustomerReturnUniqueId == null) throw new ArgumentException("Return is invalid."); returnReport.ReturnReportStatus = ReturnReportStatus.Reported; returnKeyRepository.UpdateReturnReport(returnReport); }
public List<KeyOperationResult> UpdateKeysAfterRetrieveReturnReportAck(ReturnReport returnReport, KeyStoreContext context = null) { var keys = returnReport.ReturnReportKeys; List<KeyInfo> keysInDb = GetKeysInDb(keys.Select(k => k.KeyId)); if (keysInDb == null || keysInDb.Count == 0) throw new ApplicationException("Update keys after retrieve cbr ack are not found."); List<KeyOperationResult> results = keys.Select(key => GenerateKeyOperationResult( new KeyInfo() { KeyId = key.KeyId, KeyState = KeyState.Returned }, keysInDb, (k1, k2) => ValidateKeyAfterRetrieveAck(k1, k2))).ToList(); List<KeyInfo> validKeys = results.Where(r => !r.Failed).Select(r => r.KeyInDb ?? r.Key).ToList(); foreach (KeyInfo key in validKeys) { try { key.UlsReceivingReturnAck(keys.Single(k => k.KeyId == key.KeyId)); } catch (Exception ex) { ExceptionHandler.HandleException(ex); KeyOperationResult result = results.Single(r => r.Key.KeyId == key.KeyId); result.Failed = true; result.FailedType = KeyErrorType.StateInvalid; } } List<KeyInfo> keysToUpdate = results.Where(r => !r.Failed).Select(r => r.KeyInDb ?? r.Key).ToList(); if (keysToUpdate.Count > 0) { keyRepository.UpdateKeys(keysToUpdate, false, null, false, null, context); //Insert key sync notification data except fulfilled keys return List<long> fulfilledKeyIds = keys.Where(k => k.PreProductKeyStateId == (byte)KeyState.Fulfilled).Select(k => k.KeyId).ToList(); List<KeyInfo> keysToSync = keysToUpdate.Where(k => k.KeyState == KeyState.Returned && (!fulfilledKeyIds.Contains(k.KeyId))).ToList(); if (keysToSync.Count > 0) InsertOrUpdateKeySyncNotifiction(keysToSync, context); } results.ForEach(k => k.Key.ProductKey = (k.KeyInDb == null ? null : k.KeyInDb.ProductKey)); return results; }
public void GetAndSaveCarbonCopyReturnReport(ReturnReport returnReport) { returnReport.ReturnReportStatus = ReturnReportStatus.Completed; returnKeyRepository.InsertReturnReportAndKeys(returnReport); }
private void UpdateReturnKeyAck(KeyStoreContext context, ReturnReport returnKey) { context.ReturnReports.Attach(returnKey); context.Entry(returnKey).State = EntityState.Modified; }
private List<KeyOperationResult> VerificationReturnReport(ReturnReport returnReport) { List<KeyOperationResult> results = new List<KeyOperationResult>(); List<KeyInfo> keysInDb = GetKeysInDb(returnReport.ReturnReportKeys.Select(k => k.KeyId)); foreach (var reportKey in returnReport.ReturnReportKeys) { KeyInfo key = GetKey(reportKey.KeyId, keysInDb); if (!returnReport.ReturnNoCredit && (reportKey.ReturnTypeId == ReturnRequestType.ZOE.ToString() || reportKey.ReturnTypeId == ReturnRequestType.ZOF.ToString())) { results.Add(new KeyOperationResult() { Failed = true, FailedType = KeyErrorType.Invalid, Key = key }); returnReport.ReturnReportKeys.Remove(reportKey); } if (key.KeyState == KeyState.Fulfilled && key.KeyState == KeyState.Bound && reportKey.ReturnTypeId == ReturnRequestType.ZOA.ToString()) { results.Add(new KeyOperationResult() { Failed = true, FailedType = KeyErrorType.Invalid, Key = key }); returnReport.ReturnReportKeys.Remove(reportKey); } if (key.KeyState == KeyState.ActivationDenied && key.KeyState == KeyState.ActivationEnabled && reportKey.ReturnTypeId != ReturnRequestType.ZOA.ToString()) { results.Add(new KeyOperationResult() { Failed = true, FailedType = KeyErrorType.Invalid, Key = key }); returnReport.ReturnReportKeys.Remove(reportKey); } results.Add(new KeyOperationResult() { Failed = false, Key = key }); } return results; }
public ReturnReport UpdateReturnAfterAckRetrieved(ReturnReport returnReport, KeyStoreContext context) { ReturnReport dbReturnReport = returnKeyRepository.GetReturnKey(returnReport.ReturnUniqueId.Value, context); UpdateReturnByAck(returnReport, dbReturnReport, context); return dbReturnReport; }
public static DC.ReturnReport FromServiceContract(this ReturnAck response) { DC.ReturnReport reportReturn = new DC.ReturnReport(); reportReturn.ReturnUniqueId = response.ReturnUniqueID; reportReturn.MsReturnNumber = response.MSReturnNumber; reportReturn.OemRmaDateUTC = response.OEMRMADateUTC; reportReturn.OemRmaNumber = response.OEMRMANumber; reportReturn.ReturnDateUTC = response.ReturnDateUTC; reportReturn.SoldToCustomerId = response.SoldToCustomerID; reportReturn.SoldToCustomerName = response.SoldToCustomerName; reportReturn.ReturnReportKeys.AddRange(response.ReturnAckLineItems.Select(k => new DC.ReturnReportKey { MsReturnLineNumber = k.MSReturnLineNumber, OemRmaLineNumber = k.OEMRMALineNumber, ReturnTypeId = k.ReturnTypeID, KeyId = k.ProductKeyID, LicensablePartNumber = k.LicensablePartNumber, ReturnReasonCode = k.ReturnReasonCode, ReturnReasonCodeDescription = k.ReturnReasonCodeDescription })); return reportReturn; }