コード例 #1
0
ファイル: CarService.cs プロジェクト: festelariane/mcdb
 public bool AddModel(Model model)
 {
     try
     {
         _modelRepository.Add(model);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
コード例 #2
0
ファイル: BuisnessService.cs プロジェクト: tyrgin/net-courses
        public void AddNewClient(string name, string surname, string phoneNumber, decimal balance)
        {
            var client = new Client()
            {
                Name         = name,
                Surname      = surname,
                PhoneNumber  = phoneNumber,
                Balance      = balance,
                ClientStocks = new List <Stock>()
            };

            dataContext.Add(client);
            dataContext.SaveChanges();
        }
コード例 #3
0
        /// <summary>
        /// Processes the given event <paramref name="eventData"/>
        /// </summary>
        /// <param name="eventData">Event data</param>
        public void Handle(TransactionPerformanceCalculatedEvent eventData)
        {
            var item = new TransactionPerformance(
                eventData.AggregateId,
                eventData.ProfitAbsolute,
                eventData.ProfitPercentage,
                eventData.HoldingPeriod.StartDate,
                eventData.HoldingPeriod.EndDate,
                eventData.R)
            {
                EntryEfficiency = eventData.EntryEfficiency,
                ExitEfficiency  = eventData.ExitEfficiency,
                MAEAbsolute     = eventData.MAEAbsolute,
                MFEAbsolute     = eventData.MFEAbsolute
            };

            if (_writerRepository.GetById(eventData.AggregateId) == null)
            {
                _writerRepository.Add(item);
            }
            else
            {
                _writerRepository.Update(item);
            }
        }
コード例 #4
0
        /// <summary>
        /// Processes the given event <paramref name="eventData"/>
        /// </summary>
        /// <param name="eventData">Event data</param>
        public void Handle(CalculationAddedEvent eventData)
        {
            if (_writerRepository.GetById(eventData.AggregateId) != null)
            {
                return;
            }

            var item = new Calculation(eventData.AggregateId)
            {
                Name            = eventData.Name,
                Wkn             = eventData.Wkn,
                Multiplier      = eventData.Multiplier,
                StrikePrice     = eventData.StrikePrice,
                Underlying      = eventData.Underlying,
                InitialSl       = eventData.InitialSl,
                InitialTp       = eventData.InitialTp,
                PricePerUnit    = eventData.PricePerUnit,
                OrderCosts      = eventData.OrderCosts,
                Description     = eventData.Description,
                Units           = eventData.Units,
                IsLong          = eventData.IsLong,
                OriginalVersion = eventData.Version
            };

            _writerRepository.Add(item);
        }
コード例 #5
0
        public void AddOrUpdateCustomer(string address, string authority, DateTime?dateOfBirth,
                                        DateTime?dateOfIssue, string fio, //int idCus,
                                        string passportNo, int?phoneNumber)
        {
            var customer = new CustomersModel();

            customer.Address     = address;
            customer.Authority   = authority;
            customer.DateOfBirth = dateOfBirth;
            customer.DateOfIssue = dateOfIssue;
            customer.FIO         = fio;
            //customer.IDCUS = idCus;
            customer.PassportNo  = passportNo;
            customer.PhoneNumber = phoneNumber;

            var flag = customersRepository.Items.Contains(customer);

            if (flag)
            {
                customersRepository.Update(customer);
            }
            else
            {
                customersRepository.Add(customer);
            }
        }
コード例 #6
0
        /// <summary>
        /// Processes the given event <paramref name="eventData"/>
        /// </summary>
        /// <param name="eventData">Event data</param>
        public void Handle(FeedbackAddedEvent eventData)
        {
            if (_writerRepository.GetById(eventData.AggregateId) != null)
            {
                return;
            }

            var item = new Feedback(eventData.AggregateId)
            {
                Name            = eventData.Name,
                Description     = eventData.Description,
                OriginalVersion = eventData.Version
            };

            _writerRepository.Add(item);

            //Proportion
            if (_feedbackProportionRepository.GetById(eventData.AggregateId) != null)
            {
                throw new EventHandlerException($"Feedback proportion with id: {eventData.AggregateId} shouldn't exist", typeof(FeedbackAddedEventHandler));
            }

            var overallFeedbackAmount = _transactionRepository.GetAll()
                                        .Where(t => t is ISellingTransaction).Cast <ISellingTransaction>()
                                        .Sum(transaction => transaction.Feedback.Count());

            var proportion = new FeedbackProportion(eventData.AggregateId)
            {
                FeedbackShare = 0, OverallFeedbackAmount = overallFeedbackAmount
            };

            _feedbackProportionRepository.Add(proportion);
        }
コード例 #7
0
        public void CreateModel(ModelPivot Model)
        {
            GEN_Model model = Mapper.Map <ModelPivot, GEN_Model>(Model);

            iModelRepository.Add(model);
            SaveModel();
        }
コード例 #8
0
        public virtual IActionResult Post(T entity)
        {
            if (entity == null)
            {
                return(BadRequest("Object reference not set to an instance of an object"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                repo.Add(entity);
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.InnerException.Message);
                ModelState.AddModelError("0", e.InnerException.Message);
                return(BadRequest(ModelState));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                return(BadRequest($"{e.Message}"));
            }
            return(CreatedAtRoute(String.Concat("Get", typeof(T).Name),
                                  new { id = entity.Id }, entity));
        }
コード例 #9
0
ファイル: ModelService.cs プロジェクト: ChiBaoNguyen/Test3
        public void Create(ModelViewModel model)
        {
            var newModel = Mapper.Map <ModelViewModel, Model_M>(model);

            _modelRepository.Add(newModel);

            UpdateMaintenanceItemDetail(model);

            SaveModel();
        }
コード例 #10
0
        /// <summary>
        /// Processes the given event <paramref name="eventData"/>
        /// </summary>
        /// <param name="eventData">Event data</param>
        public void Handle(StockOverallPerformanceChangedEvent eventData)
        {
            var item = _writerRepository.GetById(eventData.StockId);

            if (item == null)
            {
                _writerRepository.Add(new StockStatistics(eventData.StockId, eventData.NewProfitAbsolute));
                return;
            }

            ((StockStatistics)item).Performance += eventData.NewProfitAbsolute;
            _writerRepository.Update(item);
        }
コード例 #11
0
        /// <summary>
        /// Processes the given event <paramref name="eventData"/>
        /// </summary>
        /// <param name="eventData">Event data</param>
        public void Handle(TransactionBuyingOrderAddedEvent eventData)
        {
            if (_writerRepository.GetById(eventData.AggregateId) != null)
            {
                return;
            }

            var stock = _stockRepository.GetById(eventData.StockId);

            if (stock == null)
            {
                throw new EventHandlerException($"No Stock found with id: {eventData.StockId}", typeof(TransactionBuyingOrderAddedEventHandler));
            }

            var strategy = _strategyRepository.GetById(eventData.StrategyId);

            if (strategy == null)
            {
                throw new EventHandlerException($"No Strategy found with id: {eventData.StrategyId}", typeof(TransactionBuyingOrderAddedEventHandler));
            }

            var item = new BuyingTransaction(eventData.AggregateId)
            {
                OriginalVersion = eventData.Version,
                Description     = eventData.Description,
                Image           = eventData.Image,
                InitialSL       = eventData.InitialSL,
                InitialTP       = eventData.InitialTP,
                OrderCosts      = eventData.OrderCosts,
                OrderDate       = eventData.OrderDate,
                PricePerShare   = eventData.PricePerShare,
                Stock           = stock,
                Strategy        = strategy,
                Tag             = eventData.Tag,
                Shares          = eventData.Shares,
                Action          = "Kauf",
                PositionSize    = eventData.PositionSize,
                CRV             = eventData.CRV
            };

            _writerRepository.Add(item);

            //Add to transaction book
            _transactionBook.AddEntry(new BuyingTransactionBookEntry(
                                          eventData.StockId,
                                          eventData.AggregateId,
                                          eventData.OrderDate,
                                          eventData.Shares,
                                          eventData.PricePerShare,
                                          eventData.OrderCosts));
        }
コード例 #12
0
ファイル: ModelService.cs プロジェクト: hungds99/IOTTasks
        public async Task <Model> AddModelAsync(Model model)
        {
            Model modelAdded;

            try
            {
                model.setCreatedAt(DateTime.UtcNow);
                modelAdded = await _modelRepository.Add(model);
            }
            catch (Exception e)
            {
                throw e;
            }
            return(modelAdded);
        }
コード例 #13
0
        public bool Add(Model model)
        {
            bool result = false;
            var  chk    = modelRepository.GetById(model.id);

            if (null == chk)
            {
                modelRepository.Add(model);
                result = true;
            }
            else
            {
                // todo something
            }

            return(result);
        }
コード例 #14
0
        public IActionResult Create([FromBody] Model Model)
        {
            try
            {
                if (Model == null || !ModelState.IsValid)
                {
                    return(BadRequest("Invalid State"));
                }

                ModelRepository.Add(Model);
            }
            catch (Exception)
            {
                return(BadRequest("Error while creating"));
            }
            return(Ok(Model));
        }
コード例 #15
0
        /// <summary>
        /// Processes the given event <paramref name="eventData"/>
        /// </summary>
        /// <param name="eventData">Event data</param>
        public void Handle(StrategyAddedEvent eventData)
        {
            if (_writerRepository.GetById(eventData.AggregateId) != null)
            {
                return;
            }

            var item = new Strategy(eventData.AggregateId)
            {
                Name            = eventData.Name,
                Description     = eventData.Description,
                OriginalVersion = eventData.Version,
                Image           = eventData.Image
            };

            _writerRepository.Add(item);
        }
コード例 #16
0
        /// <summary>
        /// Processes the given event <paramref name="eventData"/>
        /// </summary>
        /// <param name="eventData">Event data</param>
        public void Handle(StockAddedEvent eventData)
        {
            if (_writerRepository.GetById(eventData.AggregateId) != null)
            {
                return;
            }

            var item = new Stock(eventData.AggregateId)
            {
                Name            = eventData.Name,
                Wkn             = eventData.Wkn,
                Type            = eventData.Type,
                LongShort       = eventData.LongShort,
                OriginalVersion = eventData.Version
            };

            _writerRepository.Add(item);
        }
コード例 #17
0
        public void SaveModel(DtoModel modelDto)
        {
            var model = new Model
            {
                Id      = modelDto.Id,
                Name    = modelDto.Name,
                BrandId = modelDto.BrandId
            };

            if (model.Id == 0)
            {
                _modelRepository.Add(model);
            }
            else
            {
                _modelRepository.Update(model);
            }
        }
コード例 #18
0
        public async Task <IActionResult> CreateModel([FromBody] SaveModelResource modelResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var model = mapper.Map <SaveModelResource, Model>(modelResource);

            modelRepository.Add(model);
            await unitOfWork.CompleteAsync();

            model = await modelRepository.GetModel(model.Id);

            var result = mapper.Map <Model, KeyValuePairResource>(model);

            return(Ok(result));
        }
コード例 #19
0
        /// <summary>
        /// Processes the given event <paramref name="eventData"/>
        /// </summary>
        /// <param name="eventData">Event data</param>
        public void Handle(TransactionDividendOrderAddedEvent eventData)
        {
            if (_writerRepository.GetById(eventData.AggregateId) != null)
            {
                return;
            }

            var stock = _stockRepository.GetById(eventData.StockId);

            if (stock == null)
            {
                throw new EventHandlerException($"No Stock found with id: {eventData.StockId}", typeof(TransactionSellingOrderAddedEventHandler));
            }

            var item = new DividendTransaction(eventData.AggregateId)
            {
                OriginalVersion = eventData.Version,
                Description     = eventData.Description,
                Image           = eventData.Image,
                OrderCosts      = eventData.OrderCosts,
                OrderDate       = eventData.OrderDate,
                PricePerShare   = eventData.PricePerShare,
                Stock           = stock,
                Tag             = eventData.Tag,
                Taxes           = eventData.Taxes,
                Shares          = eventData.Shares,
                Action          = "Dividende",
                PositionSize    = eventData.PositionSize
            };

            _writerRepository.Add(item);


            //Add to transaction book
            _transactionBook.AddEntry(new DividendTransactionBookEntry(
                                          eventData.StockId,
                                          eventData.AggregateId,
                                          eventData.OrderDate,
                                          eventData.Shares,
                                          eventData.PricePerShare,
                                          eventData.OrderCosts,
                                          eventData.Taxes));
        }
コード例 #20
0
        /// <summary>
        /// Processes the given event <paramref name="eventData"/>
        /// </summary>
        /// <param name="eventData">Event data</param>
        public void Handle(TransactionDividendCalculatedEvent eventData)
        {
            var item = new TransactionPerformance(
                eventData.AggregateId,
                eventData.ProfitAbsolute,
                eventData.ProfitPercentage,
                eventData.HoldingPeriod.StartDate,
                eventData.HoldingPeriod.EndDate,
                eventData.R);

            if (_writerRepository.GetById(eventData.AggregateId) == null)
            {
                _writerRepository.Add(item);
            }
            else
            {
                _writerRepository.Update(item);
            }
        }
コード例 #21
0
        public void AddToDatabase(Journal journal)
        {
            lock (this)
            {
                var newManager = new DAL.Models.Manager {
                    ManagerName = journal.ManagerName
                };
                var manager = _managerRepository.GetEntity(newManager);
                if (manager == null)
                {
                    _managerRepository.Add(newManager);
                    _managerRepository.SaveChanges();
                    manager = _managerRepository.GetEntity(newManager);
                }

                var newClient = new DAL.Models.Client {
                    ClientName = journal.ClientName
                };
                _clientRepository.Add(newClient);
                _clientRepository.SaveChanges();
                var client = _clientRepository.GetEntity(newClient);

                var newProduct = new DAL.Models.Product {
                    ProductName = journal.ProductName, ProductCost = journal.ProductCost
                };
                _productRepository.Add(newProduct);
                _productRepository.SaveChanges();
                var product = _productRepository.GetEntity(newProduct);

                var saleInfo = new DAL.Models.SaleInfo
                {
                    SaleDate   = journal.SaleDate,
                    ID_Manager = manager.ID_Manager,
                    ID_Client  = client.ID_Client,
                    ID_Product = product.ID_Product
                };
                _saleInfoRepository.Add(saleInfo);
                _saleInfoRepository.SaveChanges();
            }
        }
コード例 #22
0
        /// <summary>
        /// Adds the item.
        /// </summary>
        /// <param name="aggregateId">The aggregate identifier.</param>
        /// <param name="profitAbsolute">The profit absolute.</param>
        private void AddItem(Guid aggregateId, decimal profitAbsolute)
        {
            if (_modelRepository.GetById(aggregateId) != null)
            {
                return;
            }

            //Get date from transaction
            var balanceDate = _transactionRepository.GetById(aggregateId).OrderDate;

            //Get previous balance
            var lastBalance = _modelRepository.GetAll().OrderByDescending(a => a.Date).FirstOrDefault(a => a.Date < balanceDate);

            //Add new balance
            var item = new AccountBalance(aggregateId, lastBalance?.Balance + profitAbsolute ?? profitAbsolute, profitAbsolute, balanceDate);

            _modelRepository.Add(item);

            //Get future balances
            var futureAccountBalances = _modelRepository.GetAll().OrderBy(a => a.Date).Where(a => a.Date > balanceDate);

            using (var enumerator = futureAccountBalances.GetEnumerator())
            {
                var oldBalance = item.Balance;
                while (enumerator.MoveNext())
                {
                    var newBalance = new AccountBalance(
                        enumerator.Current.TransactionId,
                        oldBalance + enumerator.Current.BalanceChange,
                        enumerator.Current.BalanceChange,
                        enumerator.Current.Date);

                    _modelRepository.Update(newBalance);

                    oldBalance = newBalance.Balance;
                }
            }
        }
コード例 #23
0
        public async Task <IActionResult> Post(Model model)
        {
            try
            {
                var response = await _repository.Add(model);

                if (response != 0)
                {
                    return(Ok("Added successfully"));
                }
                else
                {
                    return(BadRequest("An error ocurred, contact IT Staff"));
                }
            }
            catch (Exception e)
            {
                //Log error
                Log.Error(e.Message);
                Log.Error(e.StackTrace);
                return(BadRequest("An error ocurred, contact IT Staff"));
            }
        }
コード例 #24
0
        /// <summary>
        /// Processes the given event <paramref name="eventData"/>
        /// </summary>
        /// <param name="eventData">Event data</param>
        public void Handle(TransactionSplitOrderAddedEvent eventData)
        {
            if (_writerRepository.GetById(eventData.AggregateId) != null)
            {
                return;
            }

            var stock = _stockRepository.GetById(eventData.StockId);

            if (stock == null)
            {
                throw new EventHandlerException($"No Stock found with id: {eventData.StockId}", typeof(TransactionSplitOrderAddedEventHandler));
            }

            var item = new SplitTransaction(eventData.AggregateId)
            {
                OriginalVersion = eventData.Version,
                OrderDate       = eventData.OrderDate,
                PricePerShare   = eventData.PricePerShare,
                Stock           = stock,
                Shares          = eventData.Shares,
                OrderCosts      = eventData.OrderCosts,
                Action          = "Split/Reverse Split",
                PositionSize    = eventData.PositionSize
            };

            _writerRepository.Add(item);


            //Add to transaction book
            _transactionBook.AddEntry(new SplitTransactionBookEntry(
                                          eventData.StockId,
                                          eventData.AggregateId,
                                          eventData.OrderDate,
                                          eventData.Shares,
                                          eventData.PricePerShare));
        }
コード例 #25
0
 public void AddModel(Model item)
 {
     ValidateModelEntry(item);
     _modelRepository.Add(item);
 }
コード例 #26
0
 public void CreateModel(Model aModel)
 {
     repository.Add(aModel);
 }
コード例 #27
0
 public bool Add(Model entity)
 {
     return(_repository.Add(entity));
 }
コード例 #28
0
 public IActionResult PostModel([FromBody] ModelModel modelModel)
 {
     _modelRepository.Add(MapModelModel(modelModel));
     return(Ok());
 }
コード例 #29
0
 public Task Add(TModel model, CancellationToken cancellationToken = default)
 => _repository.Add(model, cancellationToken);
コード例 #30
0
 public IModelObject Create(ushort id, ushort tid, ushort parentid)
 {
     repository.Add(factory.Create(id, tid, parentid));
     return(repository.Get(id));
 }