示例#1
0
        public async Task <IActionResult> Edit(Guid Id, EditBridgeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                await _mainRepository.EditAsync(new Bridge
                {
                    Id            = Id,
                    Name          = model.Name,
                    Width         = model.Width,
                    Length        = model.Length,
                    SpanNumber    = model.SpanNumber,
                    StructureType = (int)model.StructureType,
                    Comment       = model.Comment
                });

                TempData["globalMessage"] = "修改成功";

                return(RedirectToAction(nameof(Index)));
            }
            catch (DbUpdateException /* ex */)
            {
                ModelState.AddModelError("", "无法保存更改。 " +
                                         "请重试, 如果该问题仍然存在 " +
                                         "请联系系统管理员。");
                return(View());
            }
        }
示例#2
0
        // GET: Bridge/Edit/5
        public async Task <IActionResult> Edit(Guid Id)
        {
            if (Id == null)
            {
                return(NotFound());
            }
            var varToEdit = await _mainRepository.QueryByIdAsync(Id);

            var model = new EditBridgeViewModel
            {
                Id            = Id,
                Name          = varToEdit.Name,
                Width         = varToEdit.Width,
                Length        = varToEdit.Length,
                SpanNumber    = varToEdit.SpanNumber,
                StructureType = (StructureType)varToEdit.StructureType,
                Comment       = varToEdit.Comment
            };

            return(View(model));
        }