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 })); }
// 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 })); }
// GET: Invoice/Create public ActionResult Create(Invoice model) { db.Invoices.Add(model); db.SaveChanges(); return(RedirectToAction("Details", "invoice", new { id = model.Id })); }
// 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)); }
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)); }
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)); }
public bool AddSupplier(Supplier supplier) { int isExecuted = 0; db.Suppliers.Add(supplier); isExecuted = db.SaveChanges(); if (isExecuted > 0) { return(true); } return(false); }
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); }
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); }
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)); }
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(); }
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; }
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(); }
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(); }
public ActionResult Create(ConfigEmail model) { if (ModelState.IsValid) { db.Entry(model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); }
public void SaveOrder(Order order) { context.AttachRange(order.Lines.Select(l => l.Symbol)); if (order.OrderID == 0) { context.Orders.Add(order); } context.SaveChanges(); }
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); } }
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; } }
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()); }
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(); }
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)); }
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 })); }