Ejemplo n.º 1
0
 public static void CreateDefaultRegisters()
 {
     using (AriUMContext ctx = new AriUMContext("AriUMDBConnection"))
     {
         // Some registers to start
         UserGroup usp = new UserGroup() {
             Name="Technical staff"
         };
         CntWebApiVerbs.PostUserGroup(usp, ctx);
         User u = new User()
         {
             Name = "John Doe",
             Email = "*****@*****.**"
         };
         u.UserGroup = usp;
         CntWebApiVerbs.PostUser(u, ctx);
         u = new User()
         {
             Name="Martha Graham",
             Email="*****@*****.**"
         };
         u.UserGroup = usp;
         CntWebApiVerbs.PostUser(u, ctx);
     }
 }
 /// <summary>
 /// Updates the given user group
 /// </summary>
 /// <param name="id">The id of the user group to be updated</param>
 /// <param name="userGroup">User group with the modifications you want</param>
 /// <returns></returns>
 public virtual HttpResponseMessage Put(int id, UserGroup userGroup, string tk)
 {
     if (userGroup == null || id != userGroup.UserGroupId)
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest);
     }
     else
     {
         using (AriUMContext ctx = new AriUMContext("AriUMDBConnection"))
         {
             // Does it exist?
             UserGroup ug = CntWebApiVerbs.GetUserGroup(id, ctx);
             if (ug == null)
             {
                 return Request.CreateResponse(HttpStatusCode.NotFound);
             }
             else
             {
                 CntWebApiVerbs.PutUserGroup(userGroup, ctx);
                 return Request.CreateResponse(HttpStatusCode.NoContent);
             }
         }
     }
 }
 /// <summary>
 /// Creates a new user group
 /// </summary>
 /// <param name="userGroup">The user group that yo want to create</param>
 /// <returns>Url related to the new object</returns>
 public virtual HttpResponseMessage Post(UserGroup userGroup)
 {
     if (userGroup == null)
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest);
     }
     else
     {
         using (AriUMContext ctx = new AriUMContext("AriUMDBConnection"))
         {
             UserGroup uG = CntWebApiVerbs.PostUserGroup(userGroup, ctx);
             FetchStrategy fs = new FetchStrategy();
             UserGroup uGd = ctx.CreateDetachedCopy<UserGroup>(uG, fs);
             var response = Request.CreateResponse<UserGroup>(HttpStatusCode.Created, uGd);
             response.Headers.Location = GetUserGroupLocation(uGd.UserGroupId);
             return response;
         }
     }
 }
Ejemplo n.º 4
0
 public static bool DeleteUserGroup(UserGroup userGroup, AriUMContext ctx)
 {
     ctx.Delete(userGroup);
     ctx.SaveChanges();
     return true;
 }
Ejemplo n.º 5
0
 public static UserGroup PutUserGroup(UserGroup userGroup, AriUMContext ctx)
 {
     ctx.AttachCopy<UserGroup>(userGroup);
     ctx.SaveChanges();
     return userGroup;
 }
Ejemplo n.º 6
0
 public static UserGroup PostUserGroup(UserGroup userGroup, AriUMContext ctx)
 {
     ctx.Add(userGroup);
     ctx.SaveChanges();
     return userGroup;
 }