コード例 #1
0
        public async Task <IActionResult> PutAuthorizedAuthority(int id, AuthorizedAuthority authorizedAuthority)
        {
            if (id != authorizedAuthority.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #2
0
        // GET: AuthorizedAuthorities/Delete/5
        public async Task <IActionResult> Delete(int?id,
                                                 string SortOrder,
                                                 string NameFilter,
                                                 int?PageSize,
                                                 int?PageNumber)
        {
            ViewBag.SortOrder  = SortOrder;
            ViewBag.PageSize   = PageSize;
            ViewBag.PageNumber = PageNumber;
            ViewBag.NameFilter = NameFilter;
            if (id == null)
            {
                return(NotFound());
            }

            AuthorizedAuthority authorizedAuthority = null;
            HttpResponseMessage response            = await _HttpApiClient.GetAsync($"api/AuthorizedAuthorities/{id.ToString()}");

            if (response.IsSuccessStatusCode)
            {
                authorizedAuthority = await response.Content.ReadAsAsync <AuthorizedAuthority>();
            }
            if (authorizedAuthority == null)
            {
                return(NotFound());
            }

            return(View(authorizedAuthority));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] AuthorizedAuthority authorizedAuthority,
                                               string SortOrder,
                                               string NameFilter,
                                               int?PageSize,
                                               int?PageNumber)
        {
            ViewBag.SortOrder  = SortOrder;
            ViewBag.PageSize   = PageSize;
            ViewBag.PageNumber = PageNumber;
            ViewBag.NameFilter = NameFilter;
            if (id != authorizedAuthority.Id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                HttpResponseMessage response = await _HttpApiClient.PutAsJsonAsync(
                    $"api/AuthorizedAuthorities/{authorizedAuthority.Id}", authorizedAuthority);

                string OutputViewText = await response.Content.ReadAsStringAsync();

                OutputViewText = OutputViewText.Replace("<br>", Environment.NewLine);
                try
                {
                    response.EnsureSuccessStatusCode();
                }
                catch
                {
                    dynamic errors = JsonConvert.DeserializeObject <dynamic>(OutputViewText);
                    foreach (Newtonsoft.Json.Linq.JProperty property in errors.Children())
                    {
                        ModelState.AddModelError(property.Name, property.Value[0].ToString());
                    }
                    return(View(authorizedAuthority));
                }

                authorizedAuthority = await response.Content.ReadAsAsync <AuthorizedAuthority>();

                return(RedirectToAction(nameof(Index),
                                        new
                {
                    SortOrder = ViewBag.SortOrder,
                    PageSize = ViewBag.PageSize,
                    PageNumber = ViewBag.PageNumber,
                    NameFilter = ViewBag.NameFilter,
                }));
            }
            return(View(authorizedAuthority));
        }
コード例 #4
0
        public async Task <ActionResult <AuthorizedAuthority> > PostAuthorizedAuthority(AuthorizedAuthority authorizedAuthority)
        {
            _context.AuthorizedAuthority.Add(authorizedAuthority);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAuthorizedAuthority", new { id = authorizedAuthority.Id }, authorizedAuthority));
        }