Exemplo n.º 1
0
        public async Task <ActionResult> Index()
        {
            var mvcName = typeof(Controller).Assembly.GetName();
            var isMono  = Type.GetType("Mono.Runtime") != null;

            ViewData["Version"] = mvcName.Version.Major + "." + mvcName.Version.Minor;
            ViewData["Runtime"] = isMono ? "Mono" : ".NET";

            //查询
            var query = _personService.Query(c => true);

            if (!query.Any())
            {
                _personService.Add(new Models.Persons
                {
                    Id   = Guid.NewGuid(),
                    Name = "Loongle",
                    Age  = 18
                });

                await _personService.SaveChangesAsync();
            }

            query = _personService.Query(c => true);

            ViewData["query"] = query;

            log.Debug(DateTime.UtcNow.ToString());

            return(View());
        }
Exemplo n.º 2
0
 public IActionResult Add(Persons model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     model.Uid = Guid.NewGuid();
     _personsService.Add(model);
     _studentAffairsService.Add(new StudentAffairs()
     {
         PersonUid = model.Uid
     });
     return(RedirectToAction("List"));
 }
        public async Task <HttpResponseMessage> PostAsync(DTO.PersonRequest person)
        {
            try
            {
                var result = await Task.FromResult(_personsService.Add(person));

                if (!result.Errors.HasErrors)
                {
                    return(Request.CreateResponse(HttpStatusCode.Created, result.Result));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, result.Errors.ErrorMessage));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Exemplo n.º 4
0
 public Person Post([FromBody] Person value)
 {
     return(personsService.Add(value));
 }