示例#1
0
 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;
 }
示例#2
0
 public void UpdateReturnReport(ReturnReport returnKey)
 {
     using (var context = GetContext())
     {
         UpdateReturnKeyAck(context, returnKey);
         context.SaveChanges();
     }
 }
示例#3
0
 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();
     }
 }
示例#4
0
        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;
 }
示例#6
0
        //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;
        }
示例#7
0
 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);
 }
示例#8
0
 private void SaveReturnReport(ReturnReport returnReport)
 {
     returnReport.OemRmaDate = DateTime.Now;
     returnReport.ReturnReportStatus = ReturnReportStatus.Generated;
     returnReport.CustomerReturnUniqueId = Guid.NewGuid();
     returnKeyRepository.InsertReturnReportAndKeys(returnReport);
 }
示例#9
0
 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);
 }
示例#10
0
 public void UpdateReturnWhenAckFailed(ReturnReport returnReport)
 {
     returnReport.ReturnReportStatus = ReturnReportStatus.Failed;
     returnKeyRepository.UpdateReturnReport(returnReport);
 }
示例#11
0
 public void UpdateReturnReportToCarbonCopyCompleted(ReturnReport returnReport)
 {
     returnReport.ReturnReportStatus = ReturnReportStatus.CarbonCopyCompleted;
     returnKeyRepository.UpdateReturnReport(returnReport);
 }
示例#12
0
        public void UpdateReturnAfterReported(ReturnReport returnReport)
        {
            if (returnReport.CustomerReturnUniqueId == null)
                throw new ArgumentException("Return is invalid.");

            returnReport.ReturnReportStatus = ReturnReportStatus.Reported;
            returnKeyRepository.UpdateReturnReport(returnReport);
        }
示例#13
0
        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;
        }
示例#14
0
 public void GetAndSaveCarbonCopyReturnReport(ReturnReport returnReport)
 {
     returnReport.ReturnReportStatus = ReturnReportStatus.Completed;
     returnKeyRepository.InsertReturnReportAndKeys(returnReport);
 }
示例#15
0
 private void UpdateReturnKeyAck(KeyStoreContext context, ReturnReport returnKey)
 {
     context.ReturnReports.Attach(returnKey);
     context.Entry(returnKey).State = EntityState.Modified;
 }
示例#16
0
        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;
        }
示例#17
0
 public ReturnReport UpdateReturnAfterAckRetrieved(ReturnReport returnReport, KeyStoreContext context)
 {
     ReturnReport dbReturnReport = returnKeyRepository.GetReturnKey(returnReport.ReturnUniqueId.Value, context);
     UpdateReturnByAck(returnReport, dbReturnReport, context);
     return dbReturnReport;
 }
示例#18
0
        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;
        }