Ejemplo n.º 1
0
        public async Task <IHttpActionResult> Post([FromBody] TitleLevelViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var newModel = Mapper.Map <TitleLevelViewModel, TitleLevel>(viewModel);

            newModel.CreateUser = newModel.UpdateUser = User.Identity.Name;
            _titleLevelRepository.Add(newModel);
            await UnitOfWork.SaveChangesAsync();

            return(RedirectToRoute("", new { controller = "TitleLevel", id = newModel.Id }));
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> Put(int id, [FromBody] TitleLevelViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            viewModel.UpdateUser = User.Identity.Name;
            viewModel.UpdateTime = Now;
            viewModel.LastAction = "更新";
            var model = Mapper.Map <TitleLevelViewModel, TitleLevel>(viewModel);

            _titleLevelRepository.AttachAsModified(model);

            await UnitOfWork.SaveChangesAsync();

            return(Ok(viewModel));
        }