public async Task <IActionResult> PutDeviceAssigned(int id, DeviceAssigned deviceAssigned)
        {
            if (id != deviceAssigned.DeviceAssignedId)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new Response {
                    Status = "Error", Message = "No hay un dispositivo con ese ID"
                }));
            }
            try
            {
                await _deviceAssignedDAO.UpdateAsync(deviceAssigned, id);

                return(Ok(new Response {
                    Status = "OK", Message = "El registro se ha actualizado correctamente"
                }));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!await _deviceAssignedDAO.ExistAsync(id))
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response {
                        Status = "Error", Message = "No hay un dispositivo con ese ID"
                    }));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response {
                        Status = "Error", Message = "No hay un dispositivo con ese ID"
                    }));
                }
            }
        }
Пример #2
0
        public async Task <DeviceAssigned> UpdateAsync(DeviceAssigned deviceAssigned, int idAgent)
        {
            try
            {
                //TODO guardar historial
                HistoryDeviceAssigned history = new HistoryDeviceAssigned()
                {
                    CarLicence       = deviceAssigned.CarLicence,
                    Description      = deviceAssigned.Description,
                    DateAsignation   = deviceAssigned.DateAsignation,
                    StatusId         = deviceAssigned.StatusId,
                    SecurityAgentID  = deviceAssigned.SecurityAgentID,
                    DeviceAssignedId = deviceAssigned.DeviceAssignedId
                };
                await context.historyDeviceAssigneds.AddAsync(history);

                await context.SaveChangesAsync();

                //////////////
                deviceAssigned.SecurityAgentID = idAgent;
                deviceAssigned.DateAsignation  = DateTime.Now;
                context.deviceAssigneds.Update(deviceAssigned);
                await SaveAllAsync(deviceAssigned);
            }
            catch (Exception)
            {
                throw;
            }
            return(deviceAssigned);
        }
Пример #3
0
        public async Task <DeviceAssigned> CreateAsync(DeviceAssigned deviceAssigned)
        {
            await context.deviceAssigneds.AddAsync(deviceAssigned);

            await SaveAllAsync(deviceAssigned);

            return(deviceAssigned);
        }
Пример #4
0
 public async Task <bool> SaveAllAsync(DeviceAssigned deviceAssigned)
 {
     try
     {
         return(await context.SaveChangesAsync() > 0);
     }
     catch (Exception ex)
     {
         SystemLog systemLog = new SystemLog();
         systemLog.Description = ex.ToMessageAndCompleteStacktrace();
         systemLog.DateLog     = DateTime.UtcNow.ToLocalTime();
         systemLog.Controller  = GetType().Name;
         systemLog.Action      = UtilitiesAIO.GetCallerMemberName();
         systemLog.Parameter   = JsonConvert.SerializeObject(deviceAssigned);
         _customSystemLog.AddLog(systemLog);
         return(false);
     }
 }
Пример #5
0
 public async Task DeleteAsync(DeviceAssigned deviceAssigned)
 {
     context.deviceAssigneds.Remove(deviceAssigned);
     await SaveAllAsync(deviceAssigned);
 }