예제 #1
0
        public async Task <IActionResult> Refresh(TokenApiModel tokenApiModel)
        {
            if (tokenApiModel is null)
            {
                return(BadRequest("Invalid client request"));
            }

            var cookies = Request.Cookies;

            string accessToken  = tokenApiModel.AccessToken;
            string refreshToken = cookies.First(o => o.Key == "refreshToken").Value;

            var principal = _tokenService.GetPrincipalFromExpiredToken(accessToken);
            var username  = principal.Identity.Name; //this is mapped to the Name claim by default

            var user = _dbContext.AspNetUsers.SingleOrDefault(u => u.Email == username);

            if (user == null || user.RefreshToken != refreshToken || user.RefreshTokenExpiryTime <= DateTime.Now)
            {
                return(BadRequest("Invalid client request"));
            }

            var newAccessToken  = _tokenService.GenerateAccessToken(principal.Claims);
            var newRefreshToken = await _tokenService.GenerateRefreshToken(user.Email);

            user.RefreshToken = newRefreshToken;
            _dbContext.SaveChanges();

            setTokenCookie(newRefreshToken);

            return(Ok(new
            {
                accessToken = newAccessToken
            }));
        }
예제 #2
0
 // GET: Building/Create
 public ActionResult Create(Building model, int pageNo = 1)
 {
     //model.Code = AutoNumberHelper.GenerateNumber(ObjectType.Building, db);
     db.Buildings.Add(model);
     db.SaveChanges();
     return(RedirectToAction("Index", new { PageNo = pageNo }));
 }
예제 #3
0
        // GET: Invoice/Create
        public ActionResult Create(Invoice model)
        {
            db.Invoices.Add(model);
            db.SaveChanges();

            return(RedirectToAction("Details", "invoice", new { id = model.Id }));
        }
예제 #4
0
 // GET: ReceiveEmail/Create
 public ActionResult Create(ReceiveEmail model, int pageNo = 1)
 {
     if (ModelState.IsValid)
     {
         db.ReceiveEmails.Add(model);
         db.SaveChanges();
     }
     return(RedirectToAction("Index", new { PageNo = pageNo }));
 }
        public ActionResult Create([Bind(Include = "Id,CategoryName")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categorys.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
예제 #6
0
        public ActionResult Create([Bind(Include = "Id,Name,Code,CategoryId")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId);
            return(View(product));
        }
예제 #7
0
        public ActionResult Create([Bind(Include = "Id,CompanyId,ItemId,Quentity")] StockOut stockOut)
        {
            if (ModelState.IsValid)
            {
                db.StockOuts.Add(stockOut);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CompanyId = new SelectList(db.Companys, "Id", "CompanyName", stockOut.CompanyId);
            ViewBag.ItemId    = new SelectList(db.Items, "Id", "ItemName", stockOut.ItemId);
            return(View(stockOut));
        }
예제 #8
0
        public bool AddSupplier(Supplier supplier)
        {
            int isExecuted = 0;

            db.Suppliers.Add(supplier);
            isExecuted = db.SaveChanges();
            if (isExecuted > 0)
            {
                return(true);
            }

            return(false);
        }
예제 #9
0
        public ActionResult Create([Bind(Include = "Id,CategoryId,ItemId,StockInQuentity")] StockIn stockIn)
        {
            if (ModelState.IsValid)
            {
                db.StockIns.Add(stockIn);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categorys, "Id", "CategoryName", stockIn.CategoryId);
            ViewBag.ItemId     = new SelectList(db.Items, "Id", "ItemName", stockIn.ItemId);
            return(View(stockIn));
        }
        public bool AddPurchase(Purchase purchase)
        {
            int isExecuted = 0;

            db.Purchases.Add(purchase);
            isExecuted = db.SaveChanges();
            if (isExecuted > 0)
            {
                return(true);
            }

            return(false);
        }
        public bool AddCategory(Category category)
        {
            int isExecuted = 0;

            db.Categories.Add(category);
            isExecuted = db.SaveChanges();
            if (isExecuted > 0)
            {
                return(true);
            }

            return(false);
        }
예제 #12
0
        public bool AddProductSale(ProductSale productSale)
        {
            int isExecuted = 0;

            db.ProductSales.Add(productSale);
            isExecuted = db.SaveChanges();
            if (isExecuted > 0)
            {
                return(true);
            }

            return(false);
        }
        public bool AddCustomer(Customer customer)
        {
            int isExecuted = 0;

            db.Customers.Add(customer);
            isExecuted = db.SaveChanges();
            if (isExecuted > 0)
            {
                return(true);
            }

            return(false);
        }
예제 #14
0
        public ActionResult Create([Bind(Include = "Id,CategoryId,CompanyId,ItemName,ReorderLevel")] Item item)
        {
            if (ModelState.IsValid)
            {
                db.Items.Add(item);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categorys, "Id", "CategoryName", item.CategoryId);
            ViewBag.CompanyId  = new SelectList(db.Companys, "Id", "CompanyName", item.CompanyId);
            return(View(item));
        }
예제 #15
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            List <int> idListsDelete = new List <int>();

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                string chk = (string)row.Cells[0].Value;

                if (chk.Equals("1"))
                {
                    int selectedId = Int32.Parse(row.Cells[1].Value.ToString());
                    idListsDelete.Add(selectedId);
                }
            }

            if (idListsDelete.Count > 0)
            {
                foreach (int id in idListsDelete)
                {
                    con.Stocks.Where(x => x.Id == id).ToList().ForEach(x => x.DeleteFlag = "1");
                }
                con.SaveChanges();
                MessageBox.Show(Messages.DEL_OK_MSG);
                getStockList();
            }
            else
            {
                MessageBox.Show(Messages.DEL_EMPTY_MSG);
            }
        }
        private void btn_save_Click(object sender, EventArgs e)
        {
            int rowcnt = dataGridView1.RowCount;

            if (rowcnt == 1)
            {
                MessageBox.Show(Messages.REG_EMPTY_MSG);
                return;
            }

            foreach (DataGridViewRow item in dataGridView1.Rows)
            {
                if (item.Cells[0].Value == null || item.Cells[1].Value == null)
                {
                    break;
                }

                DateTime date  = DateTime.Parse(item.Cells[0].Value.ToString());
                Decimal  price = Decimal.Parse(item.Cells[1].Value.ToString());
                con.Dividend.Add(new Dividend(price, date));
            }

            con.SaveChanges();
            MessageBox.Show(Messages.REG_OK_MSG);
            dataGridView1.Rows.Clear();
            getDivList();
        }
예제 #17
0
        public void SyncLocalDatabaseWithServer()
        {
            StockDbContext localContext  = new StockDbContext("Data Source= .\\;Initial Catalog=StockDb;Persist Security Info=True;User ID=ayoobfar_ali;Password=119801;MultipleActiveResultSets=true");
            StockDbContext serverContext = new StockDbContext("Data Source = www.elecontrol.ir\\MSSQLSERVER2019; Initial Catalog = elecont1_data; Persist Security Info = True; User ID = elecont1_nejati; Password = Ali11980*; MultipleActiveResultSets = true");

            List <SymbolGroup> localSymbolGroup  = localContext.SymbolGroups.ToList();
            List <SymbolGroup> serverSymbolGroup = serverContext.SymbolGroups.ToList();

            foreach (SymbolGroup symbol in localSymbolGroup)
            {
                if (!serverSymbolGroup.Any(s => s.Id == symbol.Id))
                {
                    serverContext.SymbolGroups.Add(symbol);
                }
            }

            List <Symbol> localSymbol  = localContext.Symbols.ToList();
            List <Symbol> serverSymbol = serverContext.Symbols.ToList();

            foreach (Symbol symbol in localSymbol)
            {
                if (!serverSymbol.Any(s => s.Id == symbol.Id))
                {
                    serverContext.Symbols.Add(symbol);
                }
            }



            int numberOfChanges = serverContext.SaveChanges();

            return;
        }
예제 #18
0
        StockDbContext stockDbContext             = new StockDbContext();//todo use ioc
        public void InsertTradeInfoFromCSVFilesIntoDatabse()
        {
            List <Symbol> SymbolList = stockDbContext.Symbols.ToList <Symbol>();

            //for each stock search for csv file
            foreach (Symbol symbol in SymbolList)
            {
                List <PointData> listTradeDataFileSystem = dataLoaderFileSystem.GetStockData(symbol.SymbolLatin);
                List <TradeData> listTradeDataDatabase   = stockDbContext.TradeDatas.Where(tradeData => tradeData.SymbolId == symbol.Id).ToList <TradeData>();
                //add new data from file system to database
                foreach (PointData pointData in listTradeDataFileSystem)
                {
                    if (!listTradeDataDatabase.Any(tradeData => tradeData.Date == pointData.Date))
                    {
                        TradeData newTradeData = new TradeData();
                        newTradeData.SymbolId = symbol.Id;
                        newTradeData.FillFromPointData(pointData);

                        listTradeDataDatabase.Add(newTradeData);
                        stockDbContext.TradeDatas.Add(newTradeData);
                    }
                }
            }


            stockDbContext.SaveChanges();
        }
예제 #19
0
        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            StockDbContext stockDbContext = new StockDbContext();
            Shareholder    shareholder    = listShareholder.Find(s => s.Name == comboBoxName.SelectedItem.ToString());
            Symbol         stockInfo      = listSymbol.Find(s => s.NamePersian == comboBoxStockInfo.SelectedItem.ToString());

            TradeType tradeType     = radioButtonBuy.Checked ? TradeType.Buy : TradeType.Sell;
            int       volume        = int.Parse(textBoxVolume.Text);
            double    pricePerShare = double.Parse(textBoxPricePerShare.Text);
            double    totalPrice    = double.Parse(textBoxTotalPrice.Text);
            DateTime  date          = dateTimePicker1.Value.Date;

            StockTrading newStockTrading = new StockTrading();

            newStockTrading.ShareholderId = shareholder.Id;
            newStockTrading.SymbolId      = stockInfo.Id;
            newStockTrading.TradeType     = tradeType;
            newStockTrading.Volume        = volume;
            newStockTrading.PricePerShare = pricePerShare;
            newStockTrading.TotalPrice    = totalPrice;
            newStockTrading.Date          = date;

            try
            {
                stockDbContext.StockTradings.Add(newStockTrading);
                stockDbContext.SaveChanges();
                labelMessage.Text = "OK" + DateTime.Now.ToLongTimeString();
            }
            catch (Exception ex)
            {
                labelMessage.Text = ex.Message;
            }
        }
        private void btn_save_Click(object sender, EventArgs e)
        {
            int rowcnt = dataGridView1.RowCount;

            if (rowcnt == 1)
            {
                MessageBox.Show(Messages.REG_EMPTY_MSG);
                return;
            }

            foreach (DataGridViewRow item in dataGridView1.Rows)
            {
                if (item.Cells[0].Value == null || item.Cells[1].Value == null || item.Cells[2].Value == null)
                {
                    break;
                }

                String  symbol = item.Cells[0].Value.ToString();
                int     shares = Int16.Parse(item.Cells[1].Value.ToString());
                Decimal price  = Decimal.Parse(item.Cells[2].Value.ToString());
                con.Stocks.Add(new Stocks(symbol, shares, price));
            }

            con.SaveChanges();
            MessageBox.Show(Messages.REG_OK_MSG);
            dataGridView1.Rows.Clear();
            getStockList();
        }
예제 #21
0
 public ActionResult Create(ConfigEmail model)
 {
     if (ModelState.IsValid)
     {
         db.Entry(model).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
예제 #22
0
 public void SaveOrder(Order order)
 {
     context.AttachRange(order.Lines.Select(l => l.Symbol));
     if (order.OrderID == 0)
     {
         context.Orders.Add(order);
     }
     context.SaveChanges();
 }
예제 #23
0
        public async Task <string> GenerateRefreshToken(LoginUserDTO user)
        {
            var randomNumber = new byte[32];

            using (var rng = RandomNumberGenerator.Create())
            {
                rng.GetBytes(randomNumber);

                var hash = Convert.ToBase64String(randomNumber);

                var userObj = _dbContext.AspNetUsers.First(o => o.Email == user.Email);

                userObj.RefreshToken           = hash;
                userObj.RefreshTokenExpiryTime = DateTime.Now.AddDays(7);
                _dbContext.SaveChanges();

                return(hash);
            }
        }
예제 #24
0
        public int SaveChanges()
        {
            try
            {
                return(_dbContext.SaveChanges());
            }
            catch (OptimisticConcurrencyException ex)
            {
                Console.WriteLine(ex);
                throw;
                //TODO : handle exceptions
                throw;
                //var context = ((IObjectContextAdapter)_dbContext  ).ObjectContext;
                //// Resolve the concurrency conflict by refreshing the
                //// object context before re-saving changes.
                //context.Refresh(RefreshMode.ClientWins, orders);

                //// Save changes.
                //context.SaveChanges();
                //Console.WriteLine("OptimisticConcurrencyException "
                //+ "handled and changes saved");
            }
            catch (CommitFailedException ex)
            {
                //TODO : handle exceptions
                return(_dbContext.SaveChanges());
            }
            catch (EntityException ex)
            {
                //TODO : handle exceptions
                return(_dbContext.SaveChanges());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }
        }
예제 #25
0
        public bool SaveChanges()
        {
            try
            {
                _db.SaveChanges();
                return(true);
            }
#pragma warning disable 0168
            catch (Exception e)
#pragma warning restore 0168
            {
                return(false);
            }
        }
        public ActionResult StockIn(StockInCreateVM stockInCreate)
        {
            if (ModelState.IsValid)
            {
                StockIn stock = Mapper.Map <StockIn>(stockInCreate);

                db.StockIns.Add(stock);
                if (db.SaveChanges() > 0)
                {
                    ViewBag.Message = "Data Has been saved Successfully";
                }
                return(RedirectToAction("StockIn"));
            }
            return(View());
        }
예제 #27
0
        private void btn_reg_Click(object sender, EventArgs e)
        {
            AutoClosingMessageBox.Show(Messages.REG_MSG, "登録", 2000);

            string fistName = tb_firstName.Text;
            string lastName = tb_lastName.Text;
            string password = tb_password.Text;
            string email    = tb_email.Text;

            Users newUser = new Users(email, password, fistName, lastName, null);

            con.Users.Add(newUser);
            con.SaveChanges();
            MessageBox.Show(Messages.REG_OK_MSG);

            Utilities.PreviousPage.Show();
            this.Close();
        }
예제 #28
0
        public static string GenerateNumber(ObjectType type, StockDbContext db)
        {
            int y   = DateTime.Now.Year;
            var obj = db.AutoNumbers.SingleOrDefault(p => p.Year == y && p.Object.Equals(type.ToString(), StringComparison.OrdinalIgnoreCase));

            if (obj != null)
            {
                obj.Number++;
                db.Entry(obj).State = System.Data.Entity.EntityState.Modified;
            }
            else
            {
                obj = new AutoNumber()
                {
                    Number = 1,
                    Object = type.ToString(),
                    Year   = y,
                };
                db.AutoNumbers.Add(obj);
            }
            db.SaveChanges();

            return(string.Format("{0}{1:00000}", EnumHelper.GetDescription(type), obj.Number));
        }
예제 #29
0
 public void Create(TEntity item)
 {
     _dbSet.Add(item);
     _context.SaveChanges();
 }
 // GET: SupplierContact/Create
 public ActionResult Create(SupplierContact model, int pageNo = 1)
 {
     db.SupplierContacts.Add(model);
     db.SaveChanges();
     return(RedirectToAction("Index", new { PageNo = pageNo }));
 }