public async Task <IActionResult> PutItem(Guid id, Item item) { if (id != item.Id) { return(BadRequest()); } _context.Entry(item).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!itemService.ItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task CheckStatus() { var today = DateTime.Now.Date; var schedules = await _context.Schedules.Where(s => s.MaintenanceDate < today && s.Status == Status.Pending).ToListAsync(); if (schedules.Count() > 0) { foreach (var schedule in schedules) { schedule.Status = Status.NotAccomplished; _context.Entry(schedule).State = EntityState.Modified; } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } } }
public async Task <IActionResult> PutMaintenance(Guid id, Maintenance maintenance) { if (id != maintenance.Id) { return(BadRequest()); } _context.Entry(maintenance).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!maintenanceService.MaintenanceExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutComputer(Guid id, Computer computer) { if (id != computer.Id) { return(BadRequest()); } _context.Entry(computer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!computerService.ComputerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> StatusAccomplished(UpdateStatus updateStatus) { var result = await scheduleService.StatusAccomplished(updateStatus); if (result == null) { return(NotFound()); } result.Status = Status.Accomplished; _context.Entry(result).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(NoContent()); }
public async Task PutMaintenanceItem(MaintenanceItem maintenanceItem) { _context.Entry(maintenanceItem).State = EntityState.Modified; var scheduleItemComputersId = await(from sic in _context.ScheduleItemComputers where sic.ItemId == maintenanceItem.ItemId select new { sic.Id }).ToListAsync(); if (scheduleItemComputersId.Count() > 0) { List <ScheduleMaintenanceItem> scheduleMaintenanceItemsList = new List <ScheduleMaintenanceItem>(); foreach (var sicId in scheduleItemComputersId) { var smiList = await _context.ScheduleMaintenanceItems.Where(smi => smi.ScheduleItemComputerId == sicId.Id && smi.MaintenanceId == maintenanceItem.MaintenanceId) .ToListAsync(); scheduleMaintenanceItemsList.AddRange(smiList); } if (scheduleMaintenanceItemsList.Count > 0) { //List<Schedule> schedulesList = new List<Schedule>(); foreach (var smiObj in scheduleMaintenanceItemsList) { var schedulesList = await _context.Schedules.Where(s => s.ScheduleMaintenanceItemId == smiObj.Id).ToListAsync(); //schedulesList.AddRange(sList); if (schedulesList.Count > 0) { var scheduleStatusLastDate = DateTime.Now; var scheduleStatusPending = schedulesList.Where(sl => sl.Status == Status.Pending).ToList(); if (schedulesList.Where(sl => sl.Status != Status.Pending).Any()) { scheduleStatusLastDate = schedulesList.Where(sl => sl.Status != Status.Pending) .OrderByDescending(sl => sl.MaintenanceDate) .Select(sl => sl.MaintenanceDate) .FirstOrDefault(); } var dateYearsPeriod = scheduleStatusLastDate.AddYears(4).Year; var dateAddMonth = scheduleStatusLastDate; Schedule schedule; List <Schedule> schedules = new List <Schedule>(); while (dateAddMonth.Year < dateYearsPeriod) { schedule = new Schedule(); schedule.Id = Guid.NewGuid(); schedule.ScheduleMaintenanceItemId = smiObj.Id; schedule.Status = Status.Pending; dateAddMonth = dateAddMonth.AddMonths(maintenanceItem.Period); schedule.MaintenanceDate = dateAddMonth; schedules.Add(schedule); } if (scheduleStatusPending.Count > 0) { _context.Schedules.RemoveRange(scheduleStatusPending); } _context.Schedules.AddRange(schedules); } } } } }