Esempio n. 1
0
        public Models.Response CreateGroup(Models.GroupRequest value, Guid organization)
        {
            Models.Response response = new Models.Response();

            try
            {
                //SQL Statement
                var sqlString = "INSERT INTO groups (id, name, description, organization, primary_group, created, created_by) " +
                                "VALUES (@id, @name, @description, @organization, @primary_group, @created, @created_by)";

                //Create a new Group Id UUID
                Guid groupIdGuid = Guid.NewGuid();

                using (var connection = new NpgsqlConnection(connectionString))
                {
                    connection.Open();

                    using (var command = new NpgsqlCommand(sqlString, connection))
                    {
                        command.Parameters.AddWithValue("@id", NpgsqlTypes.NpgsqlDbType.Uuid, groupIdGuid);
                        command.Parameters.AddWithValue("@name", NpgsqlTypes.NpgsqlDbType.Text, value.Name);
                        command.Parameters.AddWithValue("@description", NpgsqlTypes.NpgsqlDbType.Text, value.Description);
                        command.Parameters.AddWithValue("@organization", NpgsqlTypes.NpgsqlDbType.Uuid, organization);
                        command.Parameters.AddWithValue("@primary_group", NpgsqlTypes.NpgsqlDbType.Bigint, 0);
                        command.Parameters.AddWithValue("@created", NpgsqlTypes.NpgsqlDbType.TimestampTz, DateTime.UtcNow);
                        command.Parameters.AddWithValue("@created_by", NpgsqlTypes.NpgsqlDbType.Uuid, value.CreatedBy);

                        command.Prepare();
                        command.ExecuteNonQuery();

                        //Log Success
                        response.Status  = "success";
                        response.Message = "group created";
                        response.Id      = groupIdGuid;
                        return(response);
                    }
                }
            }
            catch (Exception ex)
            {
                //Log Exception
                _logger.LogError(ex, "group creation failed");
                response.Status  = "error";
                response.Message = "group creation failed";
                response.Id      = errorGuid;
                return(response);
            }
        }
Esempio n. 2
0
        public Models.Response CreateGroup(Models.GroupRequest value, long organization)
        {
            Models.Response response = new Models.Response();

            try
            {
                //SQL Statement
                var sqlString = "INSERT INTO groups (id, name, description, organization) " +
                                "VALUES (@id, @name, @description, @organization)";

                //Create UNIX Timestamp
                var utcDateTime  = DateTime.UtcNow;
                var dto          = new DateTimeOffset(utcDateTime);
                var unixDateTime = dto.ToUnixTimeMilliseconds();

                using (var connection = new NpgsqlConnection(connectionString))
                {
                    connection.Open();

                    using (var command = new NpgsqlCommand(sqlString, connection))
                    {
                        command.Parameters.AddWithValue("@id", NpgsqlTypes.NpgsqlDbType.Bigint, unixDateTime);
                        command.Parameters.AddWithValue("@name", NpgsqlTypes.NpgsqlDbType.Varchar, value.Name);
                        command.Parameters.AddWithValue("@description", NpgsqlTypes.NpgsqlDbType.Varchar, value.Description);
                        command.Parameters.AddWithValue("@organization", NpgsqlTypes.NpgsqlDbType.Bigint, organization);
                        command.Prepare();
                        command.ExecuteNonQuery();

                        //Log Success
                        response.Status  = "success";
                        response.Message = "group created";
                        response.Id      = unixDateTime;
                        return(response);
                    }
                }
            }
            catch (Exception ex)
            {
                //Log Exception
                //_logger.LogError(ex, "group creation failed");
                response.Status  = "error";
                response.Message = "group creation failed";
                response.Id      = 0;
                return(response);
            }
        }
Esempio n. 3
0
        private async void btnCreateGroup_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtGroupName.Text != "" && txtGroupDescription.Text != "")
                {
                    //Capture Values
                    Models.GroupRequest groupRequest = new Models.GroupRequest();
                    groupRequest.Name        = txtGroupName.Text.Trim();
                    groupRequest.Description = txtGroupDescription.Text.Trim();

                    //Create JSON Document
                    var jsonString = JsonConvert.SerializeObject(groupRequest);

                    //Clear Values
                    txtGroupName.Clear();
                    txtGroupDescription.Clear();

                    string credentials = Program.identity.ToString() + "." + Program.securityToken.ToString();

                    //Send Data
                    ClientSDK clientSDK  = new ClientSDK();
                    string    uriString  = Program.serverURL + "/Group";
                    var       jsonResult = await clientSDK.Create(uriString, jsonString, credentials);

                    var objectResult = JsonConvert.DeserializeObject <Models.Response>(jsonResult);

                    //Add to Group List
                    ListViewItem listViewItem = new ListViewItem(objectResult.Id.ToString());
                    listViewItem.SubItems.Add(groupRequest.Name);
                    listViewItem.SubItems.Add(groupRequest.Description);
                    listViewGroups.Items.Add(listViewItem);
                }
                else
                {
                    MessageBox.Show("All fields must be properly filled-in.", "Information");
                }
            }
            catch (Exception ex)
            {
                if (ex.Message == "404")
                {
                    //No data returned
                }
                else if (ex.Message == "401")
                {
                    MessageBox.Show("The email address or password you entered is either incorrect or this user doesn't exist in the system", "Error");
                }
                else if (ex.Message == "An error occurred while sending the request.")
                {
                    MessageBox.Show("The Moab Platform is unreachable.", "Network Error");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
            finally
            {
            }
        }