public async Task <IActionResult> PutCustomer(long id, Customer customer)
        {
            if (id != customer.Id)
            {
                return(BadRequest());
            }

            _context.Entry(customer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutElevatorStatus(long id, Elevator elevator)
        {
            //save elevator in a temporary variable
            var modifiedElevator = _context.elevators.Where(e => e.Id == elevator.Id).FirstOrDefault <Elevator>();



            if (id != elevator.Id)
            {
                return(BadRequest());
            }

            _context.Entry(modifiedElevator).State = EntityState.Detached;
            _context.Entry(elevator).State         = EntityState.Modified;

            try
            {
                // replace user input with the saved elements except the field to be change by endpoint
                elevator.Id               = modifiedElevator.Id;
                elevator.model            = modifiedElevator.model;
                elevator.type_of_building = modifiedElevator.type_of_building;
                // // elevator.status = modifiedElevator.status;
                elevator.last_inspection_date   = modifiedElevator.last_inspection_date;
                elevator.inspection_certificate = modifiedElevator.inspection_certificate;
                elevator.information            = modifiedElevator.information;
                elevator.notes       = modifiedElevator.notes;
                elevator.created_at  = modifiedElevator.created_at;
                elevator.updated_at  = DateTime.Now;
                elevator.column_id   = modifiedElevator.column_id;
                elevator.customer_id = modifiedElevator.customer_id;

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ElevatorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <IActionResult> PutBatteryStatus(long id, Battery battery)
        {
            var originalBattery = _context.batteries.Where(e => e.Id == battery.Id).FirstOrDefault <Battery>();

            if (id != battery.Id)
            {
                return(BadRequest());
            }

            _context.Entry(originalBattery).State = EntityState.Detached;

            _context.Entry(battery).State = EntityState.Modified;

            try
            {
                battery.Id               = originalBattery.Id;
                battery.building_id      = originalBattery.building_id;
                battery.type_of_building = originalBattery.type_of_building;
                // battery.status = originalBattery.status;
                battery.employee_id            = originalBattery.employee_id;
                battery.commissioning_date     = originalBattery.commissioning_date;
                battery.last_inspection_date   = originalBattery.last_inspection_date;
                battery.operations_certificate = originalBattery.operations_certificate;
                battery.information            = originalBattery.information;
                battery.notes       = originalBattery.notes;
                battery.created_at  = originalBattery.created_at;
                battery.updated_at  = DateTime.Now;
                battery.customer_id = originalBattery.customer_id;



                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BatteryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutColumnStatus(long id, Column column)
        {
            var modifiedColumn = _context.columns.Where(e => e.Id == column.Id).FirstOrDefault <Column>();

            // FindAsync(id);


            if (id != column.Id)
            {
                return(BadRequest());
            }

            _context.Entry(modifiedColumn).State = EntityState.Detached;
            _context.Entry(column).State         = EntityState.Modified;

            try
            {
                column.Id = modifiedColumn.Id;
                column.type_of_building        = modifiedColumn.type_of_building;
                column.number_of_floors_served = modifiedColumn.number_of_floors_served;
                // column.status = modifiedColumn.status;
                column.information = modifiedColumn.information;
                column.notes       = modifiedColumn.notes;
                column.created_at  = modifiedColumn.created_at;
                column.updated_at  = DateTime.Now;
                column.battery_id  = modifiedColumn.battery_id;
                column.customer_id = modifiedColumn.customer_id;

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ColumnExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }