public async Task <ActionResult> AddDevice(Common.Device newDevice) { if (newDevice == null) { return new ActionResult { IsSucceeded = false, Message = "Null object received." } } ; var res = new ActionResult(); using (var db = new DBEntities()) { try { db.Devices.Add(newDevice.ToDevice()); await db.SaveChangesAsync(); res.IsSucceeded = true; } catch (Exception ex) { res.IsSucceeded = false; res.Message = ex.Message; res.ErrorMetadata = ex.StackTrace; } } return(res); }
public async Task <IHttpActionResult> Put([FromBody] Common.Device device) { var res = await DataFacade.Current.AddDevice(device); if (!res.IsSucceeded) { //TODO: Log in file if is ON return(StatusCode(HttpStatusCode.InternalServerError)); } return(Ok(res)); }
public static DataAccess.Device ToDevice(this Common.Device device) { if (device == null) { return(null); } return(new DataAccess.Device { Id = device.Id, Descriptions = device.Descriptions, Name = device.Name, OwnerName = device.OwnerName, Platform = device.Platform, RegisterationUtcDate = device.RegisterationUtcDate, }); }