Exemplo n.º 1
0
        public async Task <string> Add()
        {
            Role requestBody = await JSON.httpContextDeseriliser <Role>(Request);

            if (EmployeeManagement.IsRoleExist(requestBody.role))
            {
                Response.StatusCode = StatusCodes.Status304NotModified;
                return("Role has already been Added");
            }

            int roleCount = Connection.Sql <int>(
                $"INSERT INTO {Table.ROLES} (role) VALUES ('{requestBody.role}')",
                (reader) => reader.RecordsAffected
                );

            if (roleCount > 0)
            {
                Response.StatusCode = StatusCodes.Status201Created;
                return($"{requestBody.role} Role Successfully Added");
            }

            Response.StatusCode = StatusCodes.Status502BadGateway;
            return("Internal Error");
        }