Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">id of Equipment to fetch</param>
        /// <param name="item"></param>
        /// <response code="200">OK</response>
        /// <response code="404">Equipment not found</response>
        public virtual IActionResult EquipmentIdPutAsync(int id, Equipment item)
        {
            if (item != null)
            {
                AdjustRecord(item);

                DateTime?originalSeniorityEffectiveDate = _context.GetEquipmentSeniorityEffectiveDate(id);

                var exists = _context.Equipments
                             .Any(a => a.Id == id);

                if (exists && id == item.Id)
                {
                    _context.Equipments.Update(item);
                    // Save the changes
                    _context.SaveChanges();

                    // if seniority has changed, update blocks.
                    if ((originalSeniorityEffectiveDate == null && item.SeniorityEffectiveDate != null) ||
                        (originalSeniorityEffectiveDate != null && item.SeniorityEffectiveDate != null &&
                         originalSeniorityEffectiveDate < item.SeniorityEffectiveDate))
                    {
                        _context.UpdateBlocksFromEquipment(item);
                    }

                    var result = _context.Equipments
                                 .Include(x => x.LocalArea.ServiceArea.District.Region)
                                 .Include(x => x.DistrictEquipmentType)
                                 .Include(x => x.DumpTruck)
                                 .Include(x => x.Owner)
                                 .Include(x => x.EquipmentAttachments)
                                 .Include(x => x.Notes)
                                 .Include(x => x.Attachments)
                                 .Include(x => x.History)
                                 .First(a => a.Id == id);

                    return(new ObjectResult(result));
                }
                else
                {
                    // record not found
                    return(new StatusCodeResult(404));
                }
            }
            else
            {
                // record not found
                return(new StatusCodeResult(404));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Update equipment record
        /// </summary>
        /// <param name="id">id of Equipment to update</param>
        /// <param name="item"></param>
        /// <response code="200">OK</response>
        /// <response code="404">Equipment not found</response>
        public virtual IActionResult EquipmentIdPutAsync(int id, Equipment item)
        {
            if (item != null)
            {
                AdjustRecord(item);

                DateTime?originalSeniorityEffectiveDate = _context.GetEquipmentSeniorityEffectiveDate(id);

                bool exists = _context.Equipments
                              .Any(a => a.Id == id);

                if (exists && id == item.Id)
                {
                    _context.Equipments.Update(item);

                    // save the changes
                    _context.SaveChanges();

                    // if seniority has changed, update blocks
                    if ((originalSeniorityEffectiveDate == null && item.SeniorityEffectiveDate != null) ||
                        (originalSeniorityEffectiveDate != null && item.SeniorityEffectiveDate != null &&
                         originalSeniorityEffectiveDate < item.SeniorityEffectiveDate))
                    {
                        _context.UpdateBlocksFromEquipment(item, _configuration);
                    }

                    Equipment result = _context.Equipments
                                       .Include(x => x.LocalArea.ServiceArea.District.Region)
                                       .Include(x => x.DistrictEquipmentType)
                                       .Include(x => x.DumpTruck)
                                       .Include(x => x.Owner)
                                       .Include(x => x.EquipmentAttachments)
                                       .Include(x => x.Notes)
                                       .Include(x => x.Attachments)
                                       .Include(x => x.History)
                                       .First(a => a.Id == id);

                    return(new ObjectResult(new HetsResponse(result)));
                }

                // record not found
                return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // record not found
            return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
        }