コード例 #1
0
 public GargoyleEntity(GargoyleModel model)
 {
     this.Name    = model.Name;
     this.Color   = model.Color;
     this.Size    = model.Size;
     this.Gender  = model.Gender;
     this.Updated = model.Updated;
 }
コード例 #2
0
        public IActionResult Patch(string index, [FromBody] GargoyleModel gargoyleModel)
        {
            var model = this.gargoylesDatabase.Get(index);

            if (gargoyleModel.Color != null)
            {
                model.Color = gargoyleModel.Color;
            }

            // also, convert to an entity first
            return(Json(model));
        }
コード例 #3
0
        public void Update(GargoyleModel model)
        {
            var modelToUpdate = this.gargoyles[model.Name];

            // true if null
            // true if ""
            // true if "    "
            if (!string.IsNullOrWhiteSpace(model.Color))
            {
                modelToUpdate.Updated = DateTime.UtcNow;
                modelToUpdate.Color   = model.Color;
            }
        }
コード例 #4
0
        public GargoyleModel Update(string index, GargoyleModel model)
        {
            var modelToUpdate = this.gargoyles[index];

            // true if null
            // true if ""
            // true if "    "
            if (!string.IsNullOrWhiteSpace(model.Color))
            {
                modelToUpdate.Updated = DateTime.UtcNow;
                modelToUpdate.Color   = model.Color;
            }

            return(modelToUpdate);
        }
コード例 #5
0
        public IActionResult Put(string index, [FromBody] GargoyleModel gargoyleModel)
        {
            // we aren't doing index checking for the lecture. don't forget it

            if (!Request.Headers.TryGetValue("If-Match", out StringValues ifMatch))
            {
                return(StatusCode((int)HttpStatusCode.PreconditionFailed));
            }

            var model = this.gargoylesDatabase.Get(index);

            if (model.ETag() != ifMatch)
            {
                return(StatusCode((int)HttpStatusCode.PreconditionFailed));
            }

            this.gargoylesDatabase.AddOrReplace(gargoyleModel);

            // also, convert to an entity first
            return(Json(model));
        }
コード例 #6
0
 public void AddOrReplace(GargoyleModel model)
 {
     model.Updated = DateTime.UtcNow;
     this.gargoyles[model.Name] = model;
 }
コード例 #7
0
 public GargoyleEntity(GargoyleModel model)
 {
     this.Name  = model.Name;
     this.Color = model.Color;
 }