Example #1
0
        public IActionResult Put([FromBody] StoreViewModel model)
        {
            //return a generic HTTP Status 500 (Server Error)
            //if the client payload is invalide
            if (model == null)
            {
                return(new StatusCodeResult(500));
            }

            //mapping the store with model
            var store = model.Adapt <Store>();

            //properties taken from the request
            store.Title       = model.Title;
            store.Description = model.Description;
            store.StoreName   = model.StoreName;
            store.Text        = model.Text;
            store.Notes       = model.Notes;

            //properties set from the server side
            store.CreatedDate      = DateTime.Now;
            store.LastModifiedDate = store.CreatedDate;

            //set a temporary creater using the Admin user's userId
            //store.UserId = DbContext.Users.Where(u => u.UserName == "Admin").FirstOrDefault().Id;
            store.UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            //add the new quiz
            DbContext.Stores.Add(store);

            //persist the changes into the Database.
            DbContext.SaveChanges();

            return(new JsonResult(store.Adapt <StoreViewModel>(), JsonSettings));
        }