Beispiel #1
0
        public void TestMethod_02()
        {
            var bytes         = File.ReadAllBytes(BIN_FILE);
            var myDataStruct1 = StructureParser.Deserialize(bytes);
            var bytes1        = StructureParser.Serialize(myDataStruct1.Item1, myDataStruct1.Item2);

            Assert.IsTrue(bytes.SequenceEqual(bytes1), "Bad decoded");
        }
Beispiel #2
0
        public bool Post([FromBody] string file)
        {
            var filePath = Path.Combine(Environment.CurrentDirectory, "Upload", file);

            if (!File.Exists(filePath))
            {
                throw new AppException("File '" + file + "' is not found");
            }

            //read buffer
            var buffer = File.ReadAllBytes(filePath);
            var model  = StructureParser.Deserialize(buffer).AsModel();

            //check unique version
            var ent   = _vRepository.Find(a => a.Version == model.Version);
            var isNew = false;

            //if null
            if (ent == null)
            {
                isNew = true;
                ent   = new HeaderModel
                {
                    Type    = model.Type,
                    Version = model.Version
                };
            }
            else
            {
                //also update
                ent.Type    = model.Type;
                ent.Version = model.Version;
            }

            //migrate exists trader records
            foreach (var record in model.TradeRecords)
            {
                var trader = ent.TradeRecords.FirstOrDefault(a => a.Id == record.Id);

                if (trader == null)
                {
                    trader = new TradeRecordModel
                    {
                        Id      = record.Id,
                        Volumne = record.Volumne,
                        Account = record.Account,
                        Comment = record.Comment
                    };

                    ent.TradeRecords.Add(trader);
                }
                else
                {
                    trader.Volumne = record.Volumne;
                    trader.Account = record.Account;
                    trader.Comment = record.Comment;
                }
            }

            //add
            if (isNew)
            {
                _vRepository.Add(ent);
            }
            else
            {
                //edit
                _vRepository.Edit(ent);
            }

            return(_vRepository.Save() > 0);
        }