public async Task <IActionResult> PolicyExists() { try { var service = (MinioOSSService)_OSSService; var item = new StatementItem() { Effect = "Allow", Principal = new Principal() { AWS = new List <string>() { "*" }, }, Action = new List <string>() { "s3:GetObject" }, Resource = new List <string>() { "arn:aws:s3:::berrypi-dev/public*", }, IsDelete = false }; var result = await service.PolicyExistsAsync(_bucketName, item); return(Content(result.ToString())); } catch (Exception ex) { return(Content(ex.Message)); } }
/// <summary> /// Call once a the beginning to initialized the default values /// and once if the user changes the Statement date /// </summary> /// <param name="statementDate"></param> private void UpdateBalances(DateTime statementDate) { decimal d = this.myMoney.ReconciledBalance(this.account, statementDate); this.LastBalance = d; this.YourNewBalance = this.myMoney.ReconciledBalance(this.account, statementDate.AddMonths(1)); // in case we are re-editing a previously reconciled statement. this.statement = this.statements.GetStatement(this.account, statementDate); var stmt = this.statements.GetStatementFullPath(this.account, statementDate); this.StatementFileName.Text = stmt; decimal savedBalance = this.statements.GetStatementBalance(this.account, statementDate); if (savedBalance != 0) { this.NewBalance = savedBalance; } else { // try and compute the expected balance. this.NewBalance = this.myMoney.EstimatedBalance(this.account, statementDate); } if (StatementDateChanged != null) { StatementDateChanged(this, EventArgs.Empty); } CheckDone(false); }
/// <summary> /// Tries to store (persist) data about a given contact. /// </summary> /// <param name="contact">Contact to be persisted in the repo.</param> public void Store(StatementItem statementItem) { using (var context = new MysqlContext()) { context.Entry(statementItem).State = ((statementItem.ID == 0) ? (EntityState.Added) : (EntityState.Modified)); context.SaveChanges(); } }
/// <summary> /// Removes a given contact from the repo. /// </summary> /// <param name="contact">Contact to remove.</param> public void Remove(StatementItem statementItem) { using (var context = new MysqlContext()) { context.Entry(statementItem).State = EntityState.Deleted; context.SaveChanges(); } }
/// <summary> /// Adds a new contact to the repo. /// </summary> /// <param name="contact">Contact to add.</param> public void Add(StatementItem statementItem) { using (var context = new MysqlContext()) { context.StatementItems.Add(statementItem); context.SaveChanges(); } }
private StatementItem CheckActveUsers(Package package) { var item = new StatementItem { Name = "Usuários", Quantity = 1, Value = package.Price }; return item; }
private StatementItem CheckActveUsers(Package package) { var item = new StatementItem { Name = "Usuários", Quantity = 1, Value = package.Price }; return(item); }
/// <summary> /// Tries to load data about a given contact (according to their ID) and returns the information loaded. /// </summary> /// <param name="contact">Information identifying the contact to be loaded (their ID).</param> /// <returns>Returns the requested contact. If no such contact exists, the method should throw an exception.</returns> public StatementItem Load(StatementItem statementItem) { if (!Exists(statementItem)) { throw new Exception($"There's no such contact with ID: {statementItem.ID}"); } using (var context = new MysqlContext()) { return(context.StatementItems.Find(statementItem.ID)); } }
/// <summary> /// Retrieves and returns the invoices as statement items matching the parameters given /// </summary> /// <param name="customerID"></param> /// <param name="from"></param> /// <param name="to"></param> /// <returns></returns> public static List <StatementItem> getInvoicesForStatement(int customerID, DateTime from, DateTime to) { var list = new List <StatementItem>(); try { var query = "SELECT `Invoice`.* FROM `Invoice`" + " LEFT JOIN `Customer` ON `Invoice`.`idCustomer` = `Customer`.`idCustomer` WHERE `Customer`.`idCustomer` = @customerID AND " + "`Invoice`.`CreatedDate` >= @from AND `Invoice`.`CreatedDate` <= @to; "; var dt = new DataTable(); using (var cmd = new MySqlCommand(query, conn)) { cmd.Parameters.AddWithValue("@customerID", customerID); cmd.Parameters.AddWithValue("@from", from); cmd.Parameters.AddWithValue("@to", to); dt.Load(cmd.ExecuteReader()); } var inv = new StatementItem(); foreach (DataRow dataRow in dt.Rows) { var idInvoice = dataRow.Field <int>("idInvoice"); Invoice temp = InvoiceViewModel.getInvoice(idInvoice); float credits1 = 0; var invTotalCost = dataRow.Field <float>("TotalCost"); var createdDate = dataRow.Field <DateTime>("CreatedDate"); var balance = dataRow.Field <float>("PreviousBalance"); if (temp != null && temp.isPaid == true) { credits1 = invTotalCost; balance = balance - credits1; } inv = new StatementItem { idItem = idInvoice, charges = invTotalCost, createdDate = createdDate, itemType = ItemType.Invoice, balance = balance, credits = credits1 }; list.Add(inv); } } catch (MySqlException ex) { MessageBox.Show(ex.Message); } return(list); }
/// <summary> /// Checks the repo for a given contact (their ID and/or contactname). /// </summary> /// <param name="contact">Contact to check the repo for.</param> /// <returns>Returns true :-: the contact exists, false :-: the contact does not exist.</returns> public bool Exists(StatementItem statementItem) { using (var context = new MysqlContext()) { //var query = from u in context.StatementItems // where u.Contactname == contact.Contactname // select u; IQueryable <StatementItem> query = BuildQuery(context.StatementItems, statementItem); var exists = query.Any <StatementItem>(); return(exists); } }
/// <summary> /// Finds all contacts matching given criteria (their ID and/or contactname). /// </summary> /// <param name="contact">Criteria that the found contacts should match.</param> /// <returns>Returns a list of matching contacts.</returns> public IList <StatementItem> FindList(StatementItem statementItem) { using (var context = new MysqlContext()) { //var query = from u in context.StatementItems // where u.Contactname == contact.Contactname // select u; IQueryable <StatementItem> query = BuildQuery(context.StatementItems, statementItem); var contacts = query.ToList <StatementItem>(); return(contacts); } }
/// <summary> /// Retrieves and returns the receipts as statement items matching the parameters given /// </summary> /// <param name="customerID"></param> /// <param name="from"></param> /// <param name="to"></param> /// <returns></returns> public static List <StatementItem> getReceiptsForStatement(int customerID, DateTime from, DateTime to) { var list = new List <StatementItem>(); try { var query = "SELECT `Receipt`.* FROM `Receipt`" + " LEFT JOIN `Customer` ON `Receipt`.`idCustomer` = `Customer`.`idCustomer` WHERE `Customer`.`idCustomer` = @customerID AND " + "`Receipt`.`CreatedDate` >= @from AND `Receipt`.`CreatedDate` <= @to; "; var dt = new DataTable(); using (var cmd = new MySqlCommand(query, conn)) { cmd.Parameters.AddWithValue("@customerID", customerID); cmd.Parameters.AddWithValue("@from", from); cmd.Parameters.AddWithValue("@to", to); dt.Load(cmd.ExecuteReader()); } var inv = new StatementItem(); foreach (DataRow dataRow in dt.Rows) { var idReceipt = dataRow.Field <int>("idReceipt"); var amount = dataRow.Field <float>("Amount"); var createdDate = dataRow.Field <DateTime>("CreatedDate"); var balance = dataRow.Field <float>("PreviousBalance"); inv = new StatementItem { idItem = idReceipt, credits = amount, createdDate = createdDate, itemType = ItemType.Receipt, balance = balance }; list.Add(inv); } } catch (MySqlException ex) { MessageBox.Show(ex.Message); } return(list); }
public async Task <IActionResult> PolicyExists() { try { var service = (MinioOSSService)_ossService; var item = new StatementItem() { Effect = "Allow", Principal = new Principal() { AWS = new List <string>() { "*" }, }, Action = new List <string>() { "s3:GetObject" }, Resource = new List <string>() { $"arn:aws:s3:::{_bucketName}/public*", }, IsDelete = false }; var result = await service.PolicyExistsAsync(_bucketName, item); return(Json(new ResultObject() { Status = true, Message = result ? "策略存在" : "策略不存在", Data = item, })); } catch (Exception ex) { return(Json(new ResultObject() { Status = false, Message = ex.Message })); } }
/// <summary> /// Based on the type of the statement item calls the appropriate view method /// </summary> /// <param name="item"></param> public void viewStatementItem(StatementItem item) { switch (item.itemType) { case ItemType.Invoice: m_invoice.viewInvoice(item.idItem); BtnInvoice_Click(null, null); break; case ItemType.Receipt: m_receipt.viewReceipt(item.idItem); BtnReceipt_Click(null, null); break; case ItemType.CreditNote: m_creditNote.viewCreditNote(item.idItem); BtnCreditNote_Click(null, null); break; } }
//public List<TickerDto> GetTickers() //{ // var tickerDtos = new List<TickerDto>(); // var tickers = context.Tickers.OrderBy(p => p.Name).ToList(); // foreach (var ticker in tickers) // { // var tickerDto = ConvertToDto(ticker); // tickerDtos.Add(tickerDto); // } // return tickerDtos; //} //public TickerDto GetTicker(int id) //{ // //var tickerDto = new TickerDto(); // var ticker = context.Tickers.FirstOrDefault(p => p.Id == id); // //foreach (var ticker in tickers) // //{ // var tickerDto = ConvertToDto(ticker); // // tickerDtos.Add(tickerDto); // //} // return tickerDto; //} //public TickerDto GetTicker(string symbol) //{ // //var tickerDto = new TickerDto(); // var ticker = context.Tickers.FirstOrDefault(p => p.Symbol == symbol); // //foreach (var ticker in tickers) // //{ // var tickerDto = ConvertToDto(ticker); // // tickerDtos.Add(tickerDto); // //} // return tickerDto; //} //public List<TickerDto> GetTickersByAccount(int accountId) //{ // var tickerDtos = new List<TickerDto>(); // var tickers = context.AccountTickers.Where(p => p.AccountId == accountId).OrderBy(p=>p.Ticker1.Symbol); // foreach (var ticker in tickers) // { // var tickerDto = ConvertToDto(ticker); // tickerDtos.Add(tickerDto); // } // return tickerDtos; //} //public List<StatementItemDto> GetStatements(int accountId) //{ // var statementItemDtos = new List<StatementItemDto>(); // var statementItems = context.StatementItems.OrderBy(p => p.Ticker).ThenByDescending(p=>p.Date); ;//.Where(p => p.AccountId == accountId).OrderBy(p => p.Ticker1.Symbol); // foreach (var statementItem in statementItems) // { // var statementItemDto = ConvertToDto(statementItem); // statementItemDtos.Add(statementItemDto); // } // return statementItemDtos; //} //public List<TickerDto> GetTickers(string text) //{ // var tickerDtos = new List<TickerDto>(); // //var tickers = context.Tickers.Where(r => r.Symbol.StartsWith(text)).OrderBy(p => p.Symbol).Select(r => new { r.Id, value = r.Symbol }).ToList(); // var tickers = context.Tickers.Where(r => r.Symbol.StartsWith(text)).OrderBy(p => p.Symbol).ToList(); // foreach (var ticker in tickers) // { // var tickerDto = ConvertToDto(ticker); // tickerDtos.Add(tickerDto); // } // return tickerDtos; //} //public bool SaveTicker(TickerDto tickerDto) //{ // //var tickerDto = new TickerDto(); // //var ticker = context.Tickers.FirstOrDefault(p => p.Id == id); // //foreach (var ticker in tickers) // //{ // // var tickerModel = ConvertToModel(tickerDto); // // tickerDtos.Add(tickerDto); // //} // // var id = Int32.Parse(ticker.Id); // var Ticker = context.Tickers.FirstOrDefault(p => p.Id == tickerDto.Id); // Ticker.Name = tickerDto.Name; // Ticker.Symbol = tickerDto.Symbol; // Ticker.Active = tickerDto.Active; // Ticker.BCFirstDate = tickerDto.BCFirstDate; // Ticker.BH = tickerDto.BH; // Ticker.CBSFirstDate = tickerDto.CBSFirstDate; // Ticker.Comments = tickerDto.Comments; // Ticker.component = tickerDto.component; // Ticker.current = tickerDto.current; // Ticker.DateAdded = tickerDto.DateAdded; // Ticker.DateModified = tickerDto.DateModified; // Ticker.endDate = tickerDto.endDate; // Ticker.FirstBuy = tickerDto.FirstBuy; // Ticker.InceptionDate = tickerDto.InceptionDate; // Ticker.LastSell = tickerDto.LastSell; // Ticker.MCFirstDate = tickerDto.MCFirstDate; // Ticker.priceDecimal = tickerDto.priceDecimal; //// public System.Data.Objects.DataClasses.EntityCollection<Sell> Sells { get; set; } // Ticker.shareDecimal = tickerDto.shareDecimal; // Ticker.startDate = tickerDto.startDate; // Ticker.TickerBC = tickerDto.TickerBC; // Ticker.TickerBH = tickerDto.TickerBH; // Ticker.tickerGUID = tickerDto.tickerGUID; // Ticker.TickerYahoo = tickerDto.TickerYahoo; // Ticker.type = tickerDto.Type; // context.SaveChanges(); // return true; //} private StatementItemDto ConvertToDto(StatementItem ticker) { var statementItemDto = new StatementItemDto(); statementItemDto.AccountId = ticker.AccountId; statementItemDto.Date = ticker.Date; statementItemDto.Id = ticker.Id; statementItemDto.Name = ticker.Name; statementItemDto.Nav = ticker.Nav; statementItemDto.Shares = ticker.Shares; statementItemDto.Ticker = ticker.Ticker; statementItemDto.Value = ticker.Value; return statementItemDto; }
private IQueryable <StatementItem> BuildQuery(IQueryable <StatementItem> query, StatementItem statementItem) { if (statementItem.ID != 0) { query = query.Where(u => u.ID == statementItem.ID); }/* * if (contact.Contactname != null) * { * //query = query.Where(u => u.Contactname == contact.Contactname); * string contactname = contact.Contactname; * //if ( ! contactname.Contains('*') ) * //{ * // query = query.Where(u => u.Contactname == contactname); * //} * //else * //{ * // // For search terms like 'ba*', replace '*' with '%' and use LIKE (e.g. WHERE USERNAME LIKE 'ba%'). * // //contactname = contactname.Replace('*', '%'); * // //query = query.Where(u => SqlMethods.Like(u.Contactname, contactname)); * //} * int countStars = contactname.Count(c => c == '*'); * switch (countStars) * { * case 0: * // No asterisks (wildcards) at all. * query = query.Where(u => u.Contactname == contactname); * break; * case 1: * // One asterisk. * // One asterisk may be at the beginning, in the middle or at the end of the search term. * if (contactname.Length > 1) * { * // Expect one non-asterisk character at least. * if (contactname[0] == '*') * { * // Wildcard at the beginning of the search term. * // WHERE USERNAME LIKE '%ba' * string term = contactname.Substring(1); * query = query.Where(u => u.Contactname.EndsWith(term)); * //query = query.Where(u => u.Contactname.EndsWith(term, StringComparison.OrdinalIgnoreCase)); * } * else if (contactname[contactname.Length - 1] == '*') * { * // Wildcard at the end of the search term. * // WHERE USERNAME LIKE 'ba%' * string term = contactname.Substring(0, contactname.Length - 1); * query = query.Where(u => u.Contactname.StartsWith(term)); * //query = query.Where(u => u.Contactname.StartsWith(term, StringComparison.OrdinalIgnoreCase)); * } * else * { * // Wildcard in the middle of the search term. * // WHERE USERNAME LIKE 'na%ta' * // There must be at least 3 characters in such a string. * if (contactname.Length < 3) * { * // This should never happen. * throw new Exception($"This situation is not expected. The search term: {contactname}"); * } * string[] terms = contactname.Split('*'); * query = query.Where(u => u.Contactname.StartsWith(terms[0]) && u.Contactname.EndsWith(terms[1])); * //query = query.Where(u => u.Contactname.StartsWith(terms[0], StringComparison.OrdinalIgnoreCase) && u.Contactname.EndsWith(terms[1], StringComparison.OrdinalIgnoreCase)); * } * } * break; * case 2: * // In case of two asterisks, we expect only this: *ba*. No other variants are allowed. * if (!((contactname.IndexOf('*') == 0) && (contactname.LastIndexOf('*') == contactname.Length - 1))) * { * throw new NotSupportedException($"This search term is not supported: {contactname}"); * } * if (contactname.Length > 2) * { * // Expect one non-asterisk character at least. * // WHERE USERNAME LIKE '%ba%' * string term = contactname.Substring(1, contactname.Length - 2); * query = query.Where(u => u.Contactname.Contains(term)); * //query = query.Where(u => u.Contactname.Contains(term, StringComparison.OrdinalIgnoreCase)); * } * break; * default: * throw new NotSupportedException($"This search term is not supported: {contactname}"); * } * }*/ // ... return(query); }
/// <summary> /// Calls the view statement item method in main window /// </summary> /// <param name="item"></param> public void viewItem(StatementItem item) { mainWindow.viewStatementItem(item); }
internal void ProcessStatementItemActiveProducts(Company company, Statement statement) { var item = new StatementItem(); item.Name = "Produtos"; item.Quantity = company.Products.Count(); item.Value = 0.08m * item.Quantity; statement.StatementItems.Add(item); item = new StatementItem(); item.Name = "Imagens de Produtos"; item.Quantity = company.Products.Sum(p => p.ProductImages.Count()); item.Value = 0.04m * item.Quantity; statement.StatementItems.Add(item); }
internal void ProcessStatementItemActiveUsers(Company company, Statement statement) { var item = new StatementItem(); item.Name = "Usuários"; item.UnitCost = company.Plan.Package.Price; item.Quantity = UserActivesInMonth(statement.CompanyId, statement.PeriodBegin, statement.PeriodEnd); item.Value = company.Plan.Package.Price * item.Quantity; statement.StatementItems.Add(item); }
internal StatementEventArgs(string account, StatementItem statement) { Account = account; Statement = statement; }