Пример #1
0
        public async Task <IActionResult> PostNewRole([FromBody] WeddingRole role)
        {
            if (role.WeddingRoleId != 0)
            {
                return(BadRequest("Cannot create an existing object"));
            }

            try
            {
                await _context.AddAsync(role);

                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }

            return(CreatedAtAction("PostNewRole", role, role.WeddingRoleId));
        }
Пример #2
0
        public async Task <IActionResult> UpdateRole(int id, [FromBody] WeddingRole role)
        {
            var item = await _context.FindAsync <WeddingRole>(role.WeddingRoleId);

            if (item == null)
            {
                return(NotFound());
            }

            try
            {
                _context.Entry(role).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }

            return(NoContent());
        }