コード例 #1
0
        public ActionResult PostUserWeightLogEntry(
            int id,
            [FromBody] WeightLogEntryDTO weightLogEntry)
        {
            using (var db = new SqliteContext())
            {
                var myWeight = new WeightLogEntry
                {
                    Timestamp = DateTime.Parse(weightLogEntry.Timestamp),
                    Weight    = weightLogEntry.Value,
                    UserId    = id
                };

                db.Weights.Add(myWeight);
                db.SaveChanges();
            }

            return(StatusCode(201));
        }
コード例 #2
0
        public ActionResult PostUserWeightLogEntry(
            string id,
            [FromBody] WeightLogEntryDTO weightLogEntry)
        {
            // TODO Validate user input

            if (!ValidateUserId(this.User.Claims, id))
            {
                return(StatusCode(403, new ErrorDTO("The user is not authorized to access this data.")));
            }

            var myWeight = new WeightLogEntry
            {
                Timestamp = DateTime.Parse(weightLogEntry.Timestamp),
                Weight    = weightLogEntry.Value,
                UserId    = id
            };

            this.Database.WeightLogEntries.Add(myWeight);
            this.Database.SaveChanges();

            // TODO Return the created resource and/or a location header
            return(StatusCode(201));
        }