public static DeliveryBatchResponse ToResponse(this DeliveryBatch batch)
 {
     return(new DeliveryBatchResponse
     {
         Id = batch.Id,
         DeliveryDate = batch.DeliveryDate,
         DeliveryPackages = batch.DeliveryPackages,
         ReportFileId = batch.ReportFileId
     });
 }
Пример #2
0
        public void DeliveryBatchShouldHaveCorrectProperties()
        {
            Type type = typeof(DeliveryBatch);

            type.GetProperties().Length.Should().Be(4);
            DeliveryBatch classUnderTest = new DeliveryBatch()
            {
                Id               = 1,
                DeliveryDate     = DateTime.Now,
                DeliveryPackages = 10,
                ReportFileId     = "Test"
            };

            Assert.That(classUnderTest, Has.Property("Id").InstanceOf(typeof(Int32)));
            Assert.That(classUnderTest, Has.Property("DeliveryDate").InstanceOf(typeof(DateTime)));
            Assert.That(classUnderTest, Has.Property("DeliveryPackages").InstanceOf(typeof(int)));
            Assert.That(classUnderTest, Has.Property("ReportFileId").InstanceOf(typeof(string)));
        }
        public List <DeliveryReportItem> CreateDeliverySchedule(int limit, string spreadsheet, DateTime deliveryDate)
        {
            var deliveryData = new List <DeliveryReportItem>();
            var data         = GetData(limit, deliveryDate);
            var batch        = new DeliveryBatch
            {
                DeliveryDate     = deliveryDate,
                DeliveryPackages = data.Count,
                ReportFileId     = spreadsheet
            };

            _dbContext.DeliveryBatch.Add(batch);
            _dbContext.SaveChanges();
            foreach (var record in data)
            {
                var saveRecord = new DeliveryReportItem()
                {
                    AnnexId                   = record.Id,
                    NumberOfPackages          = 1,
                    AnyFoodHouseholdCannotEat = record.AnyFoodHouseholdCannotEat,
                    BatchId                   = batch.Id,
                    FullName                  = $"{record.FirstName} {record.LastName}",
                    FullAddress               = $"{record.AddressFirstLine} {record.AddressSecondLine} {record.AddressThirdLine}",
                    Postcode                  = record.Postcode,
                    Uprn                      = record.Uprn,
                    TelephoneNumber           = record.ContactTelephoneNumber,
                    MobileNumber              = record.ContactMobileNumber,
                    DeliveryDate              = deliveryDate,
                    LastConfirmedDeliveryDate = record.LastConfirmedFoodDelivery,
                    DeliveryNotes             = record.DeliveryNotes
                };
                _dbContext.DeliveryReportData.Add(saveRecord);
                deliveryData.Add(saveRecord);
            }
            _dbContext.SaveChanges();
            return(deliveryData);
        }
 private void InsertIntoDeliveryBatchTable(DeliveryBatch batchRecord)
 {
     _context.DeliveryBatch.Add(batchRecord);
     _context.SaveChanges();
 }
Пример #5
0
        public GenerateXMLDTO GenerateXML(int id)
        {
            GenerateXMLDTO dto = new GenerateXMLDTO();

            if (!Directory.Exists(Store.C.DELIVERY_PATH))
            {
                throw (new Exception($"Delivery Folder {Store.C.DELIVERY_PATH} Not Exists . ."));
            }

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, TimeSpan.FromMinutes(15)))
                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    List <string> IgnorableCVTs = db.CVT.Where(c => c.IsIgnorableInDelivery).Select(c => c.CVTS).ToList();
                    DeliveryBatch deliveryBatch = db.DeliveryBatches.Find(id);
                    var           outXmlPath    = Path.Combine(Store.C.DELIVERY_PATH, deliveryBatch.BatchNumber + ".xml");

                    var tanIds   = deliveryBatch.Tans.Select(t => t.Id).ToList();
                    var tanDatas = db.TanData.Where(td => tanIds.Contains(td.TanId)).ToList();
                    if (!tanDatas.Any())
                    {
                        throw new Exception($"No Curated TANs Found In Delivery Batch {deliveryBatch.BatchNumber}.");
                    }
                    xsd.RXNFILE rxnFile = new xsd.RXNFILE();
                    rxnFile.SOURCE  = "GVKbio";
                    rxnFile.FILENUM = deliveryBatch.BatchNumber;
                    rxnFile.VERSION = 2;
                    var documents = new List <xsd.DOCUMENT>();
                    foreach (var tanData in tanDatas)
                    {
                        XmlUtils.LoadMasterData(tanData);
                        xsd.RXNGRP     rxnGroup = new xsd.RXNGRP();
                        List <xsd.RXN> rxns     = new List <xsd.RXN>();
                        foreach (var reaction in tanData.Tan.Reactions)
                        {
                            #region RXNID
                            var keyProduct = tanData.Tan.Participants.Where(p => p.ReactionId == reaction.Id && p.KeyProduct == true).FirstOrDefault();
                            var rxnId      = new RXNID();
                            rxnId.RXNNUM = keyProduct?.Participant?.NUM.ToString();
                            rxnId.RXNSEQ = keyProduct?.KeyProductSeq.ToString();
                            #endregion

                            #region RXNPROCESS
                            var rxnProcess = new xsd.RXNPROCESS();
                            var xmlStages  = new List <xsd.STAGE>();

                            #region RSNs
                            rxnProcess.RSN = GetRSN(reaction, IgnorableCVTs);
                            #endregion

                            #region Stages
                            foreach (var stage in reaction.Stages)
                            {
                                var xmlStage = new xsd.STAGE();
                                #region Conditions (Sub stages)
                                var subStages = new List <xsd.SUBSTAGE>();
                                foreach (var condition in stage.StageConditions)
                                {
                                    var subStage   = new xsd.SUBSTAGE();
                                    var conditions = new List <xsd.COND>();

                                    if (!String.IsNullOrEmpty(condition.Temperature))
                                    {
                                        conditions.Add(new xsd.COND {
                                            Value = condition.Temperature, TYPE = CondType.TP
                                        });
                                    }
                                    if (!String.IsNullOrEmpty(condition.Pressure))
                                    {
                                        conditions.Add(new xsd.COND {
                                            Value = condition.Pressure, TYPE = CondType.PR
                                        });
                                    }
                                    if (!String.IsNullOrEmpty(condition.Time))
                                    {
                                        conditions.Add(new xsd.COND {
                                            Value = condition.Time, TYPE = CondType.TM
                                        });
                                    }
                                    if (!String.IsNullOrEmpty(condition.PH))
                                    {
                                        conditions.Add(new xsd.COND {
                                            Value = condition.PH, TYPE = CondType.PH
                                        });
                                    }

                                    subStage.COND = conditions.ToArray();
                                    subStages.Add(subStage);
                                }
                                xmlStage.SUBSTAGE = subStages.ToArray();
                                #endregion
                                xmlStages.Add(xmlStage);
                            }
                            rxnProcess.STAGE = xmlStages.ToArray();
                            #endregion
                            #endregion

                            #region XREFGRP
                            var xRefGroup = new xsd.XREFGRP();
                            var nrns      = new List <xsd.NRN>();
                            foreach (var tanParticipant in tanData.Tan.Participants.Where(p => p.Reaction.Id == reaction.Id && p.Participant.ChemicalType != ChemicalType.S8000))
                            {
                                xsd.NRN nrn;
                                if (!nrns.Where(n => n.NRNNUM == tanParticipant.Participant.NUM).Any())
                                {
                                    nrn = new xsd.NRN()
                                    {
                                        NRNNUM = tanParticipant.Participant.NUM,
                                        NRNREG = Int32.Parse(tanParticipant.Participant.RegNumber)
                                    };
                                    nrns.Add(nrn);
                                }
                            }
                            xRefGroup.NRN = nrns.ToArray();
                            #endregion

                            xsd.SUBDESC subDesc           = null;
                            var         s8000Participants = reaction.Tan.Participants.
                                                            Where(rp => rp.ReactionId == reaction.Id && rp.Participant.ChemicalType == ChemicalType.S8000);
                            var subDefinitions = new List <xsd.SUBDEFN>();
                            if (s8000Participants.Any())
                            {
                                foreach (var s8000Particiapnt in s8000Participants)
                                {
                                    var subDefinition = new xsd.SUBDEFN();
                                    if (!subDefinitions.Where(p => p.NRNNUM == s8000Particiapnt.Participant.NUM.ToString()).Any())
                                    {
                                        subDefinition.NRNNUM  = s8000Particiapnt.Participant.NUM.ToString();
                                        subDefinition.SUBNAME = s8000Particiapnt.Participant.Name;
                                        subDefinition.SUBLOC  = String.Join(",", s8000Particiapnt.Participant.MetaData.Select(md => md.PageNo).ToList());
                                        subDefinitions.Add(subDefinition);
                                    }
                                }
                            }
                            subDesc = new xsd.SUBDESC();
                            if (!subDefinitions.Any())
                            {
                                subDefinitions.Add(new SUBDEFN());
                            }
                            subDesc.SUBDEFN = subDefinitions.ToArray();

                            #region RXN
                            var rxn = new xsd.RXN();
                            rxn.NO    = reaction.DisplayOrder;
                            rxn.RXNID = new xsd.RXNID {
                                RXNNUM = reaction.KeyProductNum, RXNSEQ = reaction.KeyProductSequence
                            };
                            rxn.RSD        = reaction.RSD;
                            rxn.XREFGRP    = xRefGroup;
                            rxn.RXNPROCESS = rxnProcess;
                            rxn.SUBDESC    = subDesc;
                            rxns.Add(rxn);
                            #endregion
                        }
                        rxnGroup.RXN = rxns.ToArray();

                        var document = new xsd.DOCUMENT();
                        document.VIEW     = "RXN";
                        document.CAN      = tanData.Tan.CAN;
                        document.TAN      = tanData.Tan.tanNumber;
                        document.ANALYST  = 8005.ToString();
                        document.COMMENTS = tanData.Tan.CommentsForXml;
                        document.RXNGRP   = rxnGroup;
                        documents.Add(document);
                    }
                    rxnFile.DOCUMENT = documents.ToArray();
                    var serializer = new XmlSerializer(typeof(xsd.RXNFILE), String.Empty);
                    var settings   = new XmlWriterSettings
                    {
                        Indent             = false,
                        OmitXmlDeclaration = true
                    };
                    using (var writer = new StreamWriter(outXmlPath))
                        using (var xmlWriter = XmlWriter.Create(writer, settings))
                        {
                            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                            serializer.Serialize(xmlWriter, rxnFile, ns);
                        }

                    return(new GenerateXMLDTO
                    {
                        IsSuccess = true,
                        OutXmlPath = outXmlPath
                    });
                }
        }