public bool Add(IPODetailsDto entity) //adding an IPO
 {
     try
     {
         var IPODetail = new IPODetail
         {
             PricePerShare    = entity.PricePerShare,
             TotalNumOfShares = entity.TotalNumOfShares,
             OpenDate         = entity.OpenDate,
             OpenTime         = entity.OpenTime,
             Remarks          = entity.Remarks,
             //  StockExchangeCompany = context.StockExchangeCompanies.Find(entity.CompanyId, entity.StockExchangeId)
             StockExchangeId = entity.StockExchangeId,
             CompanyId       = entity.CompanyId
         };
         IPODetail.Company       = context.Companies.Find(entity.CompanyId);
         IPODetail.StockExchange = context.StockExchanges.Find(entity.StockExchangeId);
         context.IPODetails.Add(IPODetail);
         context.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public void CreateACompany(Company2 company2)
 {
     _context.Company2s.Add(new Company2()
     {
         Name   = company2.Name,
         Symbol = company2.Symbol
     });
     _context.SaveChanges();
 }
        public bool Add(CompanyDto entity)  //adding a company
        {
            try
            {
                var company = new Company
                {
                    CompanyName      = entity.CompanyName,
                    Turnover         = entity.Turnover,
                    CEO              = entity.CEO,
                    BoardOfDirectors = entity.BoardOfDirectors,
                    Brief            = entity.Brief
                                       //we are also getting stock exchange ID here
                };
                company.Sector = context.Sectors.Find(entity.SectorId);
                var sector = context.Sectors.Find(entity.SectorId);

                context.Companies.Add(company);

                //ICollection<Company> a = new HashSet<Company>();
                //a.Add(company);
                sector.Companies.Add(company);
                context.Sectors.Update(sector);

                //sector.Companies.Add(company);

                //company.CompanyId get this
                // do the below via adding object of StockExchangeCompanies
                // StockExchangeCompanies = context.StockExchangeCompanies.Add(company.CompanyId, company.StockExchangeId)

                for (int i = 0; i < entity.StockExchangeIds.Count(); i++)
                {
                    var sid = entity.StockExchangeIds[i];
                    var sec = new StockExchangeCompany
                    {
                        Company       = company,
                        StockExchange = context.StockExchanges.Find(sid)
                    };

                    context.StockExchangeCompanies.Add(sec);
                }

                context.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #4
0
        public UserAccount Add(UserAccount userAccount)
        {
            _context.UserAccounts.Add(userAccount);
            _context.SaveChanges();

            return(userAccount);
        }
        public void CreateAStockRecord(StockPrice stockPrice)
        {
            var checkValidOrNot = _context.StockPrices.Where(x => x.ComapnyId == stockPrice.ComapnyId).FirstOrDefault();

            try
            {
                _context.StockPrices.Add(new StockPrice()
                {
                    ComapnyId  = stockPrice.ComapnyId,
                    MaxPrice   = stockPrice.MaxPrice,
                    MinPrice   = stockPrice.MinPrice,
                    TradingDay = stockPrice.TradingDay,
                });
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #6
0
        public bool Add(Sector entity)
        {
            context.Add(entity);
            var isChanged = context.SaveChanges();

            if (isChanged > 0)
            {
                return(true);
            }
            return(false);
        }
 public bool Add(StockExchangeDto entity)
 {
     try
     {
         var stockexchange = new StockExchange
         {
             StockExchangeName = entity.StockExchangeName,
             Brief             = entity.Brief,
             ContactAddress    = entity.ContactAddress,
             Remarks           = entity.Remarks
         };
         context.StockExchanges.Add(stockexchange);
         var x = context.SaveChanges();
         if (x > 0)
         {
             return(true);
         }
         return(false);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
 public bool Signup(User entity)
 {
     try
     {
         entity.Confirmed = true; //giving this by default instead of via activation links
         context.Users.Add(entity);
         int updates = context.SaveChanges();
         if (updates > 0)
         {
             return(true);
         }
         return(false);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
 public void Setup()
 {
     context = new StockMarketContext(options);
     context.Sectors.AddRange(GetSectorList());
     context.SaveChanges();
 }
Пример #10
0
        public Tuple <int, string, string> UploadExcel(string filePath)
        {
            var      list           = new List <StockPrice>();
            FileInfo info           = new FileInfo(filePath);
            string   fileExtension  = info.Extension;
            string   excelConString = "";

            //Get connection string using extension
            switch (fileExtension)
            {
            // If uploaded file is Excel 1997 - 2007.
            case ".xls":
                excelConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES'";
                break;

            //If uploaded file is Excel 2007 and above
            case ".xlsx":
                excelConString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES'";
                break;
            }
            // Read data from first sheet of excel into datatable
            DataTable dt = new DataTable();

            excelConString = string.Format(excelConString, filePath);

            Tuple <int, string, string> summary;

            using (OleDbConnection excelOledbConnection = new OleDbConnection(excelConString))
            {
                using (OleDbCommand excelDbCommand = new OleDbCommand())
                {
                    using (OleDbDataAdapter excelDataAdapter = new OleDbDataAdapter())
                    {
                        excelDbCommand.Connection = excelOledbConnection;

                        excelOledbConnection.Open();
                        // Get schema from excel sheet
                        DataTable excelSchema = excelOledbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);                        // Get sheet name
                        string    sheetName   = excelSchema.Rows[0]["TABLE_NAME"].ToString();
                        excelOledbConnection.Close();

                        // Read Data from First Sheet.
                        excelOledbConnection.Open();
                        excelDbCommand.CommandText     = "SELECT * From [" + sheetName + "]";
                        excelDataAdapter.SelectCommand = excelDbCommand;
                        //Fill datatable from adapter
                        excelDataAdapter.Fill(dt);
                        excelOledbConnection.Close();

                        int    count = dt.Rows.Count;
                        string cName;
                        string sName;

                        foreach (DataRow r in dt.Rows)
                        {
                            // int i = Int32.Parse(r[1].ToString().Trim());
                            //You can try single() method instead of where.
                            //StockExchangeId = context.StockExchanges.Where(s=> s.StockExchangeName == r[1].ToString().Trim())
                            //list.Add(
                            //    new StockPrice()
                            //    {
                            //        CompanyId = int.Parse(r[0].ToString().Trim()),
                            //        StockExchangeId = int.Parse(r[1].ToString().Trim()),
                            //        CurrentPrice = Convert.ToDouble(r[2].ToString().Trim()),
                            //        Date = r[3].ToString().Trim(),
                            //        Time = r[4].ToString().Trim()
                            //    }) ;
                            DateTime t  = (DateTime)r[3];
                            var      sp = new StockPrice()
                            {
                                CompanyId       = int.Parse(r[0].ToString().Trim()),
                                StockExchangeId = int.Parse(r[1].ToString().Trim()),
                                CurrentPrice    = Convert.ToDouble(r[2].ToString().Trim()),
                                Date            = t.ToString("d").Trim(),

                                //Date = r[3].ToString().Trim(),
                                Time = r[4].ToString().Trim()
                            };
                            sp.Company       = context.Companies.Find(sp.CompanyId);
                            sp.StockExchange = context.StockExchanges.Find(sp.StockExchangeId);
                            list.Add(sp);
                            //      context.Add(sp);
                            //    var x= context.SaveChanges();
                            //  Console.WriteLine(x);
                        }
                        cName   = context.Companies.Find(list.First().CompanyId).CompanyName;
                        sName   = context.StockExchanges.Find(list.First().StockExchangeId).StockExchangeName;
                        summary = new Tuple <int, string, string>(count, cName, sName);

                        context.StockPrices.AddRange(list);  //insert list of rows to table
                        var x = context.SaveChanges();
                        Console.WriteLine(x);
                        return(summary);
                        //summary tuple returns no. of entries, company name and stock exchange name.
                    }
                }
            }
        }
Пример #11
0
 public void add(UserEntity u)
 {
     db.UserEntity.Add(u);
     db.SaveChanges();
 }
Пример #12
0
 public void addCompany(CompanyEntity c)
 {
     db.CompanyEntities.Add(c);
     db.SaveChanges();
 }
Пример #13
0
 public bool Save()
 {
     return(_context.SaveChanges() >= 0);
 }
Пример #14
0
        public RedirectResult Buy(CustomerOrder customerOrder)
        {
            string  pricestring = Request.Form["Price"].Replace(".", ",");
            decimal price;

            if (decimal.TryParse(pricestring, out price))
            {
                customerOrder.Price            = price;
                customerOrder.DateTimeCustomer = DateTime.Now;
                foreach (SellerOrder sellerOrder in db.SellerOrders.OrderBy(s => s.Price))
                {
                    if (customerOrder.Count > 0)
                    {
                        if (sellerOrder.Price <= customerOrder.Price)
                        {
                            if (sellerOrder.Count >= customerOrder.Count)
                            {
                                sellerOrder.Count -= customerOrder.Count;
                                db.Orders.Add(new Order
                                {
                                    Count             = customerOrder.Count,
                                    DateTimeCompleted = customerOrder.DateTimeCustomer,
                                    DateTimeCustomer  = customerOrder.DateTimeCustomer,
                                    DateTimeSeller    = sellerOrder.DateTimeSeller,
                                    EmailCustomer     = customerOrder.Email,
                                    EmailSeller       = sellerOrder.Email,
                                    Price             = sellerOrder.Price
                                });
                                customerOrder.Count = 0;
                            }
                            else
                            {
                                customerOrder.Count -= sellerOrder.Count;

                                db.Orders.Add(new Order
                                {
                                    Count             = sellerOrder.Count,
                                    DateTimeCompleted = customerOrder.DateTimeCustomer,
                                    DateTimeCustomer  = customerOrder.DateTimeCustomer,
                                    DateTimeSeller    = sellerOrder.DateTimeSeller,
                                    EmailCustomer     = customerOrder.Email,
                                    EmailSeller       = sellerOrder.Email,
                                    Price             = sellerOrder.Price
                                });

                                sellerOrder.Count = 0;
                            }
                        }
                    }
                }
                db.SaveChanges();

                db.SellerOrders.RemoveRange(db.SellerOrders.Where(s => s.Count == 0).ToList());

                if (customerOrder.Count > 0)
                {
                    db.CustomerOrders.Add(customerOrder);
                }

                db.SaveChanges();
            }

            return(RedirectPermanent("/Home/Index"));
        }
Пример #15
0
 public void addStockExchange(StockExchangeEntity s)
 {
     db.StockExchangeEntity.Add(s);
     db.SaveChanges();
 }