public ActionResult ChargeRegistration(int recordId) { Rules rules; FlowRecord record; using (var providerDAO = new RulesDAO()) rules = providerDAO.Get(); if (rules == null) { return(StatusCode(404, new { Message = "Não há regras base para o cálculo da fatura" })); } using (var flowRecordDAO = new FlowRecordDAO()) record = flowRecordDAO.Get(recordId); if (record == null) { return(StatusCode(404, new { Message = "Registro não encontrado" })); } if (record.Departure != null) { var permanence = record.Departure - record.Arrival; var total = rules.Tax * Convert.ToDecimal(Math.Floor(permanence.Value.TotalMinutes / rules.IntervalMinutes)); // Caso tenha permanecido menos que o intervalo de cobrança, é cobrado a taxa mínima if (total <= 0) { total += rules.Tax; } return(StatusCode(200, new Invoice() { Id = 0, GenerationDate = DateTime.Now, TaxConsidered = rules.Tax, IntervalMinutesConsidered = rules.IntervalMinutes, CompanyDebtor = record.BusRegistered.BusCompany, TotalCost = total })); } return(StatusCode(412, new { Message = "O registro deve estar fechado para ser tarifado." })); }
public static Dictionary <string, HashSet <Room> > initializeRooms() { //if (DayCare.getInstance().rooms != null) //{ // return DayCare.getInstance().rooms; //} List <string> rules_data = RulesDAO.readFile(); Dictionary <string, HashSet <Room> > temp = new Dictionary <string, HashSet <Room> >(); for (int i = 1; i < rules_data.Count; i++) { string[] line = rules_data[i].Split(","); temp.Add(line[0], new HashSet <Room>()); } rooms = temp; return(rooms); }
public ActionResult UpdateRules([FromBody] Rules rules) { try { using (var providerDAO = new RulesDAO()) if (providerDAO.Update(rules)) { return(StatusCode(200, new { Message = "Regras atualizadas" })); } return(StatusCode(304, new { Message = "Regras não atualizadas" })); } catch (Exception ex) { return(StatusCode(500, new { Message = "Erro interno ao atualizar regras" })); } }
public static Dictionary <string, GroupByAge> initializeGroups() { //if(DayCare.getInstance().groups != null) //{ // return DayCare.getInstance().groups; //} List <string> rules_data = RulesDAO.readFile(); Dictionary <string, GroupByAge> temp = new Dictionary <string, GroupByAge>(); for (int i = 1; i < rules_data.Count; i++) // Loop through List with for { string[] line = rules_data[i].Split(","); GroupByAge t = new GroupByAge(line[0]); t.groupSize = Convert.ToInt32(line[1]); t.maxGroupsInRoom = Convert.ToInt32(line[3]); temp.Add(line[0], t); } temp.Add("availableResources", new GroupByAge("availableResources")); groups = temp; return(groups); }
public ActionResult GetRules() { try { Rules rules = null; using (var rulesDAO = new RulesDAO()) rules = rulesDAO.Get(); if (rules != null) { return(StatusCode(200, rules)); } return(StatusCode(404, new { Message = "Regras não encontradas" })); } catch (Exception ex) { return(StatusCode(500, new { Message = "Erro interno ao carregar regras" })); } }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously private async void doSomething(long diff) #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { lock (synobj) { ObservedValuesDAO observedValuesDao = new ObservedValuesDAO(); ObservedValues ov = observedValuesDao.GetObservedValues(); DateTime now = DateTime.Now; // If at least one of the rules is true, code is here. ov.Duration = (ov.ActualDate != null && ov.Duration != null && ov.ActualDate.Value.Date.Equals(now.Date)) ? (ov.Duration = ov.Duration + diff) : diff; ov.ActualDate = now.Date; observedValuesDao.StoreObservedValues(ov); logger.Debug("Duration ... " + ov.Duration); // We need list of the rules. And control it. RulesDAO rulesDao = new RulesDAO(); Rule[] rules = rulesDao.ListRules(); bool canContinue = CanContinue(now, ov, rules); // If we can not continue, shutdown computer ... if (!canContinue) { logger.Info("Condition is not truthfully, run command for shutdown ..."); BaseSettings bs = baseSettings.GetBaseSettings(); if (bs.ShutdownCommand != null && bs.ShutdownCommand.Length > 0) { System.Diagnostics.Process process = System.Diagnostics.Process.Start("cmd", "/C \"" + bs.ShutdownCommand + "\""); // TODO Do something with process outputs. } } } }
public ActionResult GenerateInvoice(int companyId, [FromBody] DateTime begin) { try { Company company; Rules rules; using (var companyDAO = new CompanyDAO()) company = companyDAO.Get(companyId); if (company == null) { return(StatusCode(404, new { Message = "Empresa não encontrada" })); } using (var providerDAO = new RulesDAO()) rules = providerDAO.Get(); if (rules == null) { return(StatusCode(404, new { Message = "Não há regras base para o cálculo da fatura" })); } using (var invoiceDAO = new InvoiceDAO()) { var invoice = new Invoice() { GenerationDate = DateTime.Now, CompanyDebtor = company.Id, TaxConsidered = rules.Tax, IntervalMinutesConsidered = rules.IntervalMinutes }; invoice.Id = invoiceDAO.Add(invoice); if (invoice.Id != 0) { using (var flowRecordDAO = new FlowRecordDAO()) { List <FlowRecord> records; decimal total = 0; flowRecordDAO.MarkCharge(invoice.Id, company.Id, begin, begin.AddDays(company.InvoiceInterval)); records = invoiceDAO.GetInvoiceRecords(invoice.Id); Parallel.ForEach(records, (record) => { // Calcula o valor para o período de permanência desse Ônibus com base no intervalo de cobrança e o valor da tarifa var permanence = record.Departure - record.Arrival; total += rules.Tax * Convert.ToDecimal(Math.Floor(permanence.Value.TotalMinutes / rules.IntervalMinutes)); // Caso tenha permanecido menos que o intervalo de cobrança, é cobrado a taxa mínima if (total <= 0) { total += rules.Tax; } }); if (records.Count <= 0 && invoiceDAO.Cancel(invoice.Id)) { return(StatusCode(304, new { Message = "Não há registros não faturados para este período" })); } if (invoiceDAO.SetInvoiceValue(invoice.Id, total)) { invoice = invoiceDAO.Get(invoice.Id); return(StatusCode(200, invoice)); } } } return(StatusCode(304, new { Message = "A fatura não foi gerada" })); } } catch (Exception ex) { return(StatusCode(500, new { Message = "Erro interno ao gerar fatura" })); } }