コード例 #1
0
ファイル: DataFacade.cs プロジェクト: Sigma-DG/LogCentral
        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);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
ファイル: Extentions.cs プロジェクト: Sigma-DG/LogCentral
        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,
            });
        }