Exemplo n.º 1
0
 public async Task<RateTableInfo> AddNew(RateTableInfo newInfo)
 {
     RateTable t = RateTable.New(newInfo);
     m_DbContext.RateTables.Add(t);
     await m_DbContext.SaveChangesAsync();
     return t.ToRateTableInfo();
 }
Exemplo n.º 2
0
 public void UpdateRateTable(RateTableInfo info)
 {
     Variant = info.Variant;
     VersionNumber = info.VersionNumber;
     CarrierId = info.CarrierId;
     CarrierDetails = info.CarrierDetails;
     ValidFrom = info.ValidFrom;
     Culture = info.Culture;
     //associated package files can't be updated by now
 }
        public async Task<ApiResponse<RateTableInfo>> UpdateRateTable(RateTableInfo info, string authToken)
        {
            info.ValidFrom = new DateTime(info.ValidFrom.Year, info.ValidFrom.Month, info.ValidFrom.Day, 0, 0, 0, DateTimeKind.Utc);

            RestRequest request = GetNewRequest();
            request.Resource = "Update";
            request.Method = Method.POST;
            request.AddBody(info);

            return await Execute<RateTableInfo>(request, m_RateTableApi, authToken);
        }
Exemplo n.º 4
0
 public static RateTable New(RateTableInfo info)
 {
     RateTable r = new RateTable();
     List<RateTableFile> fileList = new List<RateTableFile>();
     r.UpdateRateTable(info);
     foreach (RateTableFileInfo fileInfo in info.PackageFiles)
     {
         fileList.Add(RateTableFile.New(fileInfo));
     }
     r.PackageFiles = fileList;
     return r;
 }
        private void ExtractMetaData(RateTableInfo rateTable)
        {
            //find the meta info file
            RateTableFileInfo metaFile = rateTable.PackageFiles.FirstOrDefault(f => f.FileType == EFileType.Meta);
            if (null != metaFile)
            {
                using (MemoryStream stream = new MemoryStream(metaFile.FileData.ToArray()))
                {
                    XPathDocument doc = new XPathDocument(stream);
                    XPathNavigator nav = doc.CreateNavigator();

                    XPathNodeIterator iter = CreateIterator(GENERAL_QUERY, nav);
                    if (iter.Count == 1)
                    {
                        iter.MoveNext();
                        rateTable.Variant = ReadStringAttribute(VARIANT, iter);
                        rateTable.VersionNumber = ReadStringAttribute(VERSION, iter);
                    }

                    iter = CreateIterator(FILE_QUERY, nav);
                    while (iter.MoveNext())
                    {
                        string fileName = ReadStringAttribute(FILE_NAME, iter);
                        long crc = NumberConverter.TryParse<long>(ReadStringAttribute(CRC, iter), long.TryParse);
                        RateTableFileInfo fileInfo = rateTable.PackageFiles.FirstOrDefault(f => f.FileName == fileName);
                        if(null != fileInfo)
                        {
                            //set crc information
                            fileInfo.Checksum = crc;
                        }
                    }

                    iter = CreateIterator(PRODUCT_TABLE_QUERY, nav);
                    if (iter.Count == 1)
                    {
                        iter.MoveNext();
                        rateTable.CarrierId = NumberConverter.TryParse<int>(ReadStringAttribute(CARRIER, iter), int.TryParse);
                        rateTable.CarrierDetails = NumberConverter.TryParse<int>(ReadStringAttribute(CARRIER_DETAILS, iter), int.TryParse);
                    }
                }
            }
        }
        public async Task<ActionResult> Create([Bind(Include = "ValidFrom,Culture,ZipUpload")] RateTableViewModel rateTableViewModel, HttpPostedFileBase upload)
        {
            if (upload == null || upload.ContentLength == 0)
            {
                ModelState.AddModelError("ZipUpload", "This field is required");
            }
            else if (upload.ContentType != "application/x-zip-compressed")
            {
                ModelState.AddModelError("ZipUpload", "Please choose a zip archive.");
            }
            if (ModelState.IsValid)
            {
                //add basic stuff
                RateTableInfo rateTableInfo = new RateTableInfo();
                rateTableInfo.Culture = rateTableViewModel.Culture;
                rateTableInfo.ValidFrom = rateTableViewModel.ValidFrom;

                //add the files
                ScenarioResult<List<RateTableFileInfo>> extractResult = ExtractScenario.Execute(upload.InputStream);
                if(extractResult.Success)
                {
                    rateTableInfo.PackageFiles = extractResult.Value;
                    ScenarioResult metaResult = ReadMetaScenario.Execute(rateTableInfo);
                    if(metaResult.Success)
                    {
                        //parsing meta file succeeded - information is stored in rateTableInfo
                        //add new item to database
                        ApiResponse<RateTableInfo> response = await m_Repository.AddNewRateTable(rateTableInfo, GetAuthToken());
                        return HandleApiResponse(response, RedirectToAction("Index"), new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                    }
                }
                ModelState.AddModelError("ZipUpload", "Error processing RateTable file");
            }

            return View(rateTableViewModel);
        }
 public async Task<IHttpActionResult> AddNewRateTable(RateTableInfo info)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
     RateTableInfo resultEntry = await m_Manager.AddNew(info);
     return Ok(resultEntry);
 }
 public async Task<IHttpActionResult> UpdateTable(RateTableInfo info)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
     RateTableInfo resultEntry = await m_Manager.Update(info);
     if(null == resultEntry)
     {
         return NotFound();
     }
     return Ok(resultEntry);
 }
 public ScenarioResult Execute(RateTableInfo rateTable)
 {
     return m_ScenarioRunner.Run(() => ExtractMetaData(rateTable));
 }
Exemplo n.º 10
0
 public async Task<RateTableInfo> Update(RateTableInfo updatedInfo)
 {
     RateTable table = await m_DbContext.RateTables.FirstOrDefaultAsync(r => r.Id == updatedInfo.Id);
     if(null != table)
     {
         table.UpdateRateTable(updatedInfo);
         m_DbContext.Entry(table).State = EntityState.Modified;
         await m_DbContext.SaveChangesAsync();
         return table.ToRateTableInfo();
     }
     return null;
 }