Example #1
0
        public IActionResult EditShare(int Id, int CountryId, double CurrentPrice, string ImgSrc, string CompanyName)
        {
            string comment = "";

            using (var db = new BrokerContext())
            {
                var share = db.Shares.FirstOrDefault(x => x.Id == Id);
                if (share != null)
                {
                    if (share.CurrentPrice != CurrentPrice)
                    {
                        var historyPrice = new HistoryPriceShare()
                        {
                            Price = share.CurrentPrice, DateHistory = DateTime.Now, ShareId = share.Id
                        };
                        db.HistoryPriceShares.Add(historyPrice);
                        db.SaveChanges();
                    }
                    share.CompanyName  = CompanyName;
                    share.CurrentPrice = CurrentPrice;
                    share.ImgSrc       = ImgSrc;
                    share.Country      = db.Countries.FirstOrDefault(x => x.Id == CountryId);
                    db.Shares.Update(share);
                    db.SaveChanges();
                    comment = "Изменения, добавлены успешно";
                }
                else
                {
                    comment = "Произошла ошибка, возможно акция уже удалена";
                }
            }
            return(Ok(comment));
        }
Example #2
0
 public IActionResult AddShare(int CountryId, double CurrentPrice, string ImgSrc, string CompanyName)
 {
     using (var db = new BrokerContext())
     {
         var share = new Share();
         share.CompanyName  = CompanyName;
         share.ImgSrc       = ImgSrc;
         share.Country      = db.Countries.FirstOrDefault(x => x.Id == CountryId);
         share.CurrentPrice = CurrentPrice;
         db.Shares.Add(share);
         db.SaveChanges();
         var idShare      = db.Shares.FirstOrDefault(x => x.CompanyName == share.CompanyName).Id;
         var historyPrice = new HistoryPriceShare()
         {
             DateHistory = DateTime.Now, Price = share.CurrentPrice, ShareId = idShare
         };
         db.HistoryPriceShares.Add(historyPrice);
         db.SaveChanges();
     }
     return(Ok());
 }