public IActionResult Edit(Guid?id)
        {
            var allTeams      = _reserveBotContext.Teams.ToList();
            var resourceTypes = (ResourceType[])Enum.GetValues(typeof(ResourceType));

            var model = new EditResourceViewModel
            {
                Teams         = allTeams.Select(x => ToSelectListItem(x)).ToList(),
                ResourceTypes = resourceTypes.Select(x => new SelectListItem(x.ToString(), x.ToString())).ToList()
            };

            if (!id.HasValue)
            {
                return(View(model));
            }

            var resource = _reserveBotContext.Resources.Single(x => x.Id == id.Value);

            model.Id                   = resource.Id;
            model.Name                 = resource.Name;
            model.SelectedTeam         = resource.TeamId;
            model.SelectedResourceType = resource.ResourceType;

            return(View(model));
        }
        public IActionResult Edit(EditResourceViewModel model)
        {
            var resource = !model.Id.HasValue
                ? new ResourceEntity()
                : _reserveBotContext.Resources.Single(x => x.Id == model.Id);

            resource.Name         = model.Name;
            resource.TeamId       = model.SelectedTeam;
            resource.ResourceType = model.SelectedResourceType;

            if (!model.Id.HasValue)
            {
                _reserveBotContext.Resources.Add(resource);
            }

            _reserveBotContext.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public IActionResult Edit([FromBody] EditResourceViewModel model)
        {
            var resource = resourceService.Detail(model.Id);

            if (resource == null)
            {
                return(APIResult.记录不存在);
            }

            var check = CheckParent(model.ParentId);

            if (check.Code != APIResult.OK)
            {
                return(check);
            }

            resource = resourceService.Edit(model.Id, model.Content, model.Name, model.Authorize, model.Type, model.ParentId, model.Sort);

            return(resource != null ? APIResult.成功 : APIResult.失败);
        }