예제 #1
0
        public async Task<IHttpActionResult> CreateGroup(UserGroup group)
        {
            group.ClientId = this.ClientId;

            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            // generate group id
            group.UserGroupId = this.db.UserGroups.Count();

            // set parent id to root. i.e. -1
            group.ParentId = -1;

            this.db.UserGroups.Add(group);
            this.db.SaveChanges();

            return this.Ok(group);
        }
예제 #2
0
        public async Task<IHttpActionResult> UpdateGroup(int id, UserGroup group)
        {
            group.ClientId = this.ClientId;

            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            if (id != group.UserGroupId)
            {
                return this.BadRequest();
            }

            this.db.Entry(group).State = EntityState.Modified;

            try
            {
                this.db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!this.GroupExists(id))
                {
                    return this.NotFound();
                }

                throw;
            }

            return this.StatusCode(HttpStatusCode.NoContent);
        }