public IHttpActionResult PutUserRole(int id, UserRole userRole)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != userRole.UserRoleID)
            {
                return BadRequest();
            }

            db.Entry(userRole).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserRoleExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
        public IHttpActionResult PostUserRole(UserRole userRole)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.UserRoles.Add(userRole);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = userRole.UserRoleID }, userRole);
        }
示例#3
0
        /// <summary>
        /// Converts this instance of <see cref="UserRoleDTO"/> to an instance of <see cref="UserRole"/>.
        /// </summary>
        /// <param name="dto"><see cref="UserRoleDTO"/> to convert.</param>
        public static UserRole ToEntity(this UserRoleDTO dto)
        {
            if (dto == null) return null;

            var entity = new UserRole();

            entity.UserRoleID = dto.UserRoleID;
            entity.UserID = dto.UserID;
            entity.RoleID = dto.RoleID;

            dto.OnEntity(entity);

            return entity;
        }
示例#4
0
 /// <summary>
 /// Invoked when <see cref="ToEntity"/> operation is about to return.
 /// </summary>
 /// <param name="entity"><see cref="UserRole"/> converted from <see cref="UserRoleDTO"/>.</param>
 static partial void OnEntity(this UserRoleDTO dto, UserRole entity);