public OperationResult CreateUserGroup(ServiceDataContracts.UserGroup userGroup)
        {
            try
            {
                var dbContext = new AlohaDb();

                var group = new Entities.UserGroup();
                group.Name = userGroup.Name;

                dbContext.UserGroups.Add(group);
                dbContext.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                    CreatedObjectId = group.Id
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
        public IHttpActionResult AddNewGroupUsers([FromBody] Entities.UserGroup usergroup)
        {
            var db = new PetaPoco.Database("AGSoftware");

            var b = db.SingleOrDefault <Entities.UserGroup>("Select * from UserGroup Where UserGroupId = @0", usergroup.UserGroupId);

            Entities.UserGroupUser usergroupuser = null;

            foreach (Entities.AspNetUsers user in usergroup.Users)
            {
                //todo see if there is a better way to do this with normalization and/or one connection.
                var db2 = new PetaPoco.Database("AGSoftware");
                usergroupuser             = new Entities.UserGroupUser();
                usergroupuser.UserGroupId = usergroup.UserGroupId;
                usergroupuser.UserId      = db2.SingleOrDefault <Entities.AspNetUsers>("Select Id from AspNetUsers where Id = @0", user.Id).Id;;
                db2.Insert(usergroupuser);
            }

            return(Ok());
        }
        public IHttpActionResult Post([FromUri] string id, [FromBody] Entities.UserGroup usergroup)
        {
            var db = new PetaPoco.Database("AGSoftware");

            usergroup.UserId      = Storytime.Providers.UserHelper.GetUserId(this.User.Identity.Name);
            usergroup.DateCreated = System.DateTime.Now;
            db.Insert(usergroup);

            Entities.UserGroupUser usergroupuser = null;

            foreach (Entities.AspNetUsers user in usergroup.Users)
            {
                //todo see if there is a better way to do this with normalization and/or one connection.
                var db2 = new PetaPoco.Database("AGSoftware");
                usergroupuser             = new Entities.UserGroupUser();
                usergroupuser.UserGroupId = usergroup.UserGroupId;
                usergroupuser.UserId      = db2.SingleOrDefault <Entities.AspNetUsers>("Select Id from AspNetUsers where Id = @0", user.Id).Id;;
                db2.Insert(usergroupuser);
            }

            return(Ok(usergroup.UserGroupId));
        }