コード例 #1
0
        public async Task <ActionResult> Update([Required] int id, string?title, string?description)
        {
            if (string.IsNullOrWhiteSpace(title) && description == null)
            {
                return(BadRequest("You have to provide title or desciption!"));
            }

            var projectToUpdate = await _projectDatabase.FindOrDefault(id);

            if (projectToUpdate == null)
            {
                return(NotFound("Project with this id doesn't exists!"));
            }
            if (!string.IsNullOrWhiteSpace(title))
            {
                projectToUpdate.Title = title;
            }
            if (description != null)
            {
                projectToUpdate.Description = description;
            }
            await _projectDatabase.AddOrUpdate(projectToUpdate);

            return(NoContent());
        }
コード例 #2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            await _context.AddOrUpdate(Project);

            return(RedirectToPage("./Index"));
        }