public async Task <IActionResult> Edit(int id, [Bind("id,ServiceOrderID,Json")] LittleTask littleTask) { if (id != littleTask.id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(littleTask); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LittleTaskExists(littleTask.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(littleTask)); }
public IActionResult AddWorkload(int id, DateTime date, DateTime start, DateTime end, double kM) { if (date == DateTime.MinValue) { date = DateTime.Now.Date; } if (start == DateTime.MinValue) { start = DateTime.Now; } if (end == DateTime.MinValue) { end = DateTime.Now.AddHours(1); } var workload = end.Subtract(start).TotalHours; TempData["date"] = date.ToString("yyyy-MM-dd"); TempData["start"] = start.ToString("hh:mm"); TempData["end"] = end.ToString("hh:mm"); int iD = 0; if (_context.LittleTask.Any() == false) { iD = 1; } else { var ID = _context.LittleTask.Last(x => x.id != 0).id; ID++; iD = ID; } LittleTask littleTask = new LittleTask(); littleTask.id = iD; littleTask.Start = start; littleTask.End = end; //var JAJA = Convert.ToDouble(workload, new CultureInfo("pt-BR")); littleTask.BetweenBoth = Convert.ToDouble(workload.ToString("N2")); littleTask.kM = kM; littleTask.ServiceOrderID = id; littleTask.Date = date; _context.LittleTask.Add(littleTask); _context.SaveChanges(); //roda método pra atualizar a service order _serviceOrderService.TotalValues(id); //var json = JsonConvert.SerializeObject(charger); var order = _context.ServiceOrder.Where(s => s.id == id).First(); return(RedirectToAction(nameof(ViewDetails), new { id = order.id })); }
public IActionResult DeleteLittleTask(LittleTask little) { var littleTask = _context.LittleTask.Where(l => l.id == little.id).First(); _context.LittleTask.Remove(littleTask); _context.SaveChanges(); var serviceOrderId = littleTask.ServiceOrderID; _serviceOrderService.TotalValues(serviceOrderId); return(GoBackToListOfDays()); }
public async Task <IActionResult> Create([Bind("id,ServiceOrderID,Json")] LittleTask littleTask) { if (ModelState.IsValid) { _context.Add(littleTask); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(littleTask)); }
public IActionResult EditLittleTask(LittleTask little) { var littleTask = _context.LittleTask.Where(l => l.id == little.id).First(); littleTask.Start = little.Start; littleTask.End = little.End; littleTask.kM = little.kM; var workload = little.End.Subtract(little.Start).TotalHours; littleTask.BetweenBoth = Convert.ToDouble(workload.ToString("N2")); var serviceOrderId = littleTask.ServiceOrderID; _serviceOrderService.TotalValues(serviceOrderId); return(GoBackToListOfDays()); }
public void TotalValues(int id) { //Esse método vai atualizar tudo na service order. //pegar owner var owner = _context.Owner.FirstOrDefault(); //pegar order var order = _context.ServiceOrder.Where(x => x.id == id).First(); //gera list com todas littletask var list = _context.LittleTask.Where(x => x.ServiceOrderID == id).ToList(); //criar listas usando como key a data. Ou seja, cada data vai ter uma lista com as littletasks referentes a ela. IEnumerable <IGrouping <DateTime, int> > query = list.GroupBy(x => x.Date, x => x.id); //vai criar uma nova lista de littetasks. var listOfLittleTasks = new List <LittleTask>(); //vai criar uma littletask nova que irá receber como date a key de uma das listas criadas, e depois disso //em between hours vai ir a soma de todas as horas da lista da key citada. //isso será feito para todas as listas de key. foreach (IGrouping <DateTime, int> littleTasks in query) { double __workload = 0.00; LittleTask __littleTask = null; // puxada do banco LittleTask __littleTask__ = new LittleTask(); //nova, que recebe key como date e sum total como between hours. foreach (int ID in littleTasks) { __littleTask = list.FirstOrDefault(x => x.id == ID); __workload += __littleTask.BetweenBoth; __littleTask__.BetweenBoth = __workload; __littleTask__.Date = __littleTask.Date; __littleTask__.kM += __littleTask.kM; if (__littleTask__.BetweenBoth >= owner.TimeToMealTicket) //verifica se precisa de VR { __littleTask__.MealTicket = true; } } listOfLittleTasks.Add(__littleTask__); //adicionou todas as listas de littletask com key como date e between hours como total sum } order.NormalHours = 0.00; order.OnTheRach = 0.00; order.Overtime = 0.00; order.MealTicket = 0; order.AmountOfHours = 0.00; order.TotalEarned = 0.00; _context.Update(order); _context.SaveChanges(); foreach (var little in listOfLittleTasks) { if (little.BetweenBoth > owner.NormalTime) { var gap = little.BetweenBoth - owner.NormalTime; order.Overtime += gap; order.NormalHours += little.BetweenBoth - gap; order.AmountOfHours += little.BetweenBoth; } else { order.NormalHours += little.BetweenBoth; order.AmountOfHours += little.BetweenBoth; } order.OnTheRach += little.kM; if (little.MealTicket == true) { order.MealTicket++; order.TotalEarned += owner.MealTicket; } } //Pq ele está simplesmente ignorando esses códigos abaixo????? order.MealTicketValue = order.MealTicket * owner.MealTicket; order.TotalEarned += order.NormalHours * owner.PricePerHour; order.TotalEarned += order.Overtime * owner.PricePerHour; var profitRate = owner.OvertimeProfitRate / 100; order.TotalEarned += order.Overtime * owner.PricePerHour * profitRate; //order.TotalEarned += order.OnTheRach * owner.GasPrice; order.TotalEarned += order.OnTheRach; ///////////////// até aqui _context.Update(order); _context.SaveChanges(); }