public async Task <IActionResult> Edit(int id, [Bind("Id,Name,ParentID")] AppTestChildModel appTestChildModel)
        {
            if (id != appTestChildModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(appTestChildModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AppTestChildModelExists(appTestChildModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(appTestChildModel));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,ParentID")] AppTestChildModel appTestChildModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(appTestChildModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            PopulateParentsDropDownList(appTestChildModel.ParentID);
            return(View(appTestChildModel));
        }
Пример #3
0
        public async Task <ActionResult <AppTestChildModel> > PostAppTestChildModel(AppTestChildModel appTestChildModel)
        {
            if (ModelState.IsValid)
            {
                var existParent = await _context.AppTestModel.FindAsync(appTestChildModel.ParentID);

                if (existParent == null)
                {
                    return(BadRequest());
                }

                appTestChildModel.Parent = existParent;

                _context.AppTestChildModels.Add(appTestChildModel);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetAppTestChildModel", new { id = appTestChildModel.Id }, appTestChildModel));
            }
            else
            {
                // zhenying: upper level thrown error so this part doesn't seem like would be called.
                return(BadRequest(ModelState));
            }
        }
Пример #4
0
        public async Task <IActionResult> PutAppTestChildModel(int id, AppTestChildModel appTestChildModel)
        {
            if (id != appTestChildModel.Id)
            {
                return(BadRequest());
            }

            var existParent = await _context.AppTestModel.FindAsync(appTestChildModel.ParentID);

            if (existParent == null)
            {
                return(BadRequest());
            }

            appTestChildModel.Parent = existParent;

            _context.Entry(appTestChildModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AppTestChildModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }