コード例 #1
0
        public async Task <JsonResult> SaveSample([FromBody] SampleModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    model.CreatedBy   = User.Identity.Name;
                    model.CreatedDate = DateTime.Now;

                    await _operation.SaveAsync(model);

                    return(new JsonResult("Save Successful"));
                }

                return(new JsonResult("Model is invalid")
                {
                    StatusCode = 401
                });
            }
            catch (Exception ex)
            {
                return(new JsonResult(ex)
                {
                    StatusCode = 401
                });
            }
        }
コード例 #2
0
        public async Task Save(SampleModel model)
        {
            // You can use userName or use Identity
            model.CreatedBy = "AspNetCore.MongoDB";

            model.CreatedDate = DateTime.Now;

            await _operation.SaveAsync(model);
        }