Пример #1
0
        public IHttpActionResult PutRole(int id, Role role)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != role.RoleID)
            {
                return BadRequest();
            }

            try
            {
                db.UpdateRole(id, role);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoleExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Пример #2
0
        public Role CreateRole(Role role)
        {
            db.Roles.Add(role);
            db.SaveChanges();

            return role;
        }
Пример #3
0
        public Role Create(Role oRole)
        {
            if (oRole != null)
            {
                return oRoleRepos.CreateRole(oRole);
            }

            return null;
        }
Пример #4
0
        public IHttpActionResult PostRole(Role role)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.CreateRole(role);

            return CreatedAtRoute("DefaultApi", new { id = role.RoleID }, role);
        }
Пример #5
0
        public void UpdateRole(int id, Role role)
        {
            db.Entry(role).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
        }
Пример #6
0
        /// <summary>
        /// Converts this instance of <see cref="RoleDTO"/> to an instance of <see cref="Role"/>.
        /// </summary>
        /// <param name="dto"><see cref="RoleDTO"/> to convert.</param>
        public static Role ToEntity(this RoleDTO dto)
        {
            if (dto == null) return null;

            var entity = new Role();

            entity.RoleID = dto.RoleID;
            entity.Name = dto.Name;
            entity.Precedence = dto.Precedence;

            dto.OnEntity(entity);

            return entity;
        }
Пример #7
0
 /// <summary>
 /// Invoked when <see cref="ToEntity"/> operation is about to return.
 /// </summary>
 /// <param name="entity"><see cref="Role"/> converted from <see cref="RoleDTO"/>.</param>
 static partial void OnEntity(this RoleDTO dto, Role entity);